当我使用Jest运行我的Jasmine测试时,会出现错误:
G:\git\diamant\SpaUI\node_modules\linqts\dist\src\index.js:10
export { default as List } from './list';
^^^^^^
SyntaxError: Unexpected token export
> 1 | import { List } from 'linqts';
| ^
2 | import { ReportMessageData } from './../models/report.model';
3 | import { TranslateService } from '@ngx-translate/core';
4 | import { Injectable } from '@angular/core';
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (src/app/feature-modules/report/services/report-message-flatten.service.ts:1:1)
我知道我需要告诉Jest将代码转换为纯JavaScript,但我不知道如何做到这一点。我的jest.config.js
如下:
var preset = require("jest-preset-angular/jest-preset");
module.exports = {
...preset,
preset: "jest-preset-angular",
transformIgnorePatterns: ["<rootDir>/node_modules/(?!linqts)"],
testMatch: ["**/*.test.ts"],
globals: {
...preset.globals,
"ts-jest": {
...preset.globals["ts-jest"],
tsConfig: "src/tsconfig.test.json",
isolatedModules: true
}
},
moduleNameMapper: {
'^@diamant/feature-modules(.*)$': '<rootDir>/src/app/feature-modules/$1',
}
};