【发布时间】:2021-03-10 20:02:38
【问题描述】:
我正在尝试测试 spfx webpart 组件,但出现以下错误:
Test suite failed to run
Cannot find module 'WebPartContentStrings' from 'WebContentContainer.tsx'
我做了一些挖掘,发现在我的组件内部我做了以下事情:
import * as strings from "WebPartContentStrings";
我有这个文件:
declare module 'WebPartContentStrings' {
const strings: IWebPartContentStrings;
export = strings;
}
但是,当我模拟组件时,Jest 似乎无法正确解释导入指令并且无法找到该模块,即使当我将其托管在服务器上时应用程序可以找到它。有没有办法以不同的方式为 Jest 导入字符串?
【问题讨论】: