相关疑难解决方法(0)

为角度配置Jest

根据网络配置玩笑的角度对各种指南是那么容易,因为这个

ng new jest-test
cd jest-test
npm i -D jest jest-preset-angular
Run Code Online (Sandbox Code Playgroud)

修改package.json

"test": "jest",
[...]
"jest": {
    "preset": "jest-preset-angular",
    "setupTestFrameworkScriptFile": "./src/setup-jest.ts"
},
Run Code Online (Sandbox Code Playgroud)

setup-jest.ts

import 'jest-preset-angular';
Run Code Online (Sandbox Code Playgroud)

但是,在运行时,npm test我会不断遇到此错误:

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs angular

5
推荐指数
1
解决办法
1655
查看次数

标签 统计

angular ×1

jestjs ×1

typescript ×1