我在 @awrsome-cordova 库上遇到 ionic 6 Angular 14 Jest 设置错误。
这是我的错误:
npm test
ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
transform: {
<transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
FAIL src/app/pages/side-menu-exp/side-menu-exp.page.spec.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Details:
\node_modules\@awesome-cordova-plugins\adjust\index.js:16
import { AwesomeCordovaNativePlugin, cordova } from '@awesome-cordova-plugins/core';
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 13 | import { AdjustConfig, Adjust, AdjustEnvironment, AdjustLogLevel, AdjustEvent } from '@awesome-cordova-plugins/adjust'
| ^
这个答案将为您指明正确的方向。
确保您已安装所有必需的软件包。您需要
jest
、ts-jest
、@types/jest
和 @angular-builders/jest
。您可以像这样使用 NPM 安装:
npm install --save-dev jest ts-jest @types/jest @angular-builders/jest
按照上面链接中的答案进行操作,您就可以开始了。