【发布时间】:2020-01-11 14:08:59
【问题描述】:
我已经使用 --typescript 启动了一个 Create React App 项目。当我写一个测试我得到一个编译器错误:
// something-test.tsx
test('something', ()=>{
expect(1).toBe(1)
})
错误是:
TS1208:如果提供了“--isolatedModules”标志,所有文件都必须是模块。
通过谷歌搜索,我认为解决方法是创建一个 jest.config.tsx:
module.exports = {
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"]
};
然而这并没有什么不同。
【问题讨论】:
标签: typescript jestjs create-react-app