根据网络配置玩笑的角度对各种指南是那么容易,因为这个:
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)