【发布时间】:2023-04-10 00:30:01
【问题描述】:
我遇到了一个我不太了解的问题,所以我请求您尝试帮助我解决和理解它。
我几天以来一直在进行测试以稳定我的应用程序。我的应用程序是用 ReactJs 和 typeScript 编写的,但我的测试只写成 Js(因为我认为这对类型测试不是很有用,没关系)
因此,对于 ts 测试,它工作得非常好 12 个套件中的 9 个通过了,但是 12 个套件中的 3 个对 tsx 文件进行了测试,然后并没有真正起作用……就像开玩笑一样,请注意理解 tsx 文件,对吗?
我遇到了这样的错误:
● 测试套件无法运行
SyntaxError: /Users/***/function.spec.js: Unexpected token, expected "," (44:16)
42 | }
43 | wrapper = mount(
> 44 | <Provider store={store}>
| ^
45 | <HookWrapper />
46 | </Provider>
47 | );
at Object._raise (../../../../../usr/local/lib/node_modules/jest/node_modules/@babel/parser/src/parser/error.js:60:45)
或其他类似的:
● 测试套件无法运行
SyntaxError: /Users/***/index.spec.js: Unexpected token, expected "," (32:34)
30 | it("Run file/index is ran", async () => {
> 32 | wrapper = shallow(<ComponentFile {...minProps} />);
| ^
33 | expect(wrapper).toBeTruthy();
34 | });
35 |
at Object._raise (../../../../../usr/local/lib/node_modules/jest/node_modules/@babel/parser/src/parser/error.js:60:45)
jest.config.js
module.exports = {
verbose: true,
collectCoverage: true,
coveragePathIgnorePatterns: [],
forceCoverageMatch: [" */*.spec.js"],
testEnvironment: "jsdom",
moduleFileExtensions: ["ts", "tsx", "js"],
};
我过了一天才明白出了什么问题,但无事可做...我尝试了很多开玩笑的配置,因为我认为问题来自它,但我没有成功
【问题讨论】:
标签: reactjs typescript jestjs