Vuejs2 Vue Jest(Jest单元测试):语法错误:无法在模块外部使用导入语句
我是Vue单元测试新手,在尝试第一次测试后,我一直会遇到相同的错误。它似乎适用于前两个导入语句,但不适用于epis微调器语句。我尝试了所有方法,并在论坛和Github上查找了很多内容,但我找不到解决方案。我尝试的一切似乎都不起作用。我需要帮助 谢谢:) 错误Vuejs2 Vue Jest(Jest单元测试):语法错误:无法在模块外部使用导入语句,vuejs2,jestjs,Vuejs2,Jestjs,我是Vue单元测试新手,在尝试第一次测试后,我一直会遇到相同的错误。它似乎适用于前两个导入语句,但不适用于epis微调器语句。我尝试了所有方法,并在论坛和Github上查找了很多内容,但我找不到解决方案。我尝试的一切似乎都不起作用。我需要帮助 谢谢:) 错误 PASS test/jesttest.spec.js (5.243s) ● Console console.log test/jesttest.spec.js:18 red FAIL test/ExitU
PASS test/jesttest.spec.js (5.243s)
● Console
console.log test/jesttest.spec.js:18
red
FAIL test/ExitUserCompany.spec.js
● Test suite failed to run
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 can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
C:\9raya\anforderungsportal\anforderungsportal\frontend\node_modules\epic-spinners\src\lib.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import HollowDotsSpinner from './components/lib/HollowDotsSpinner.vue';
^^^^^^
SyntaxError: Cannot use import statement outside a module
73 | import {CompanyService} from "@/common/api/company.service";
74 | import {AssetDBDataService} from "@/common/api/assetDBData.service";
> 75 | import { SelfBuildingSquareSpinner } from 'epic-spinners'
| ^
76 |
77 | moment.locale('de');
78 |
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1059:14)
at src/layouts/MainLayout.vue:75:1
at Object.<anonymous> (src/layouts/MainLayout.vue:290:3)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 22.188s
babel.config.js
module.exports = {
plugins: [
[
"import",
{ libraryName: "ant-design-vue", libraryDirectory: "es", style: true }
],
"@babel/plugin-syntax-dynamic-import"
]
}
npm i -D @vue/babel-preset-app
//babel.config.js
module.exports = {
presets: [
'@vue/app'
]
};
你能试试下面的吗 安装npm模块
module.exports = {
plugins: [
[
"import",
{ libraryName: "ant-design-vue", libraryDirectory: "es", style: true }
],
"@babel/plugin-syntax-dynamic-import"
]
}
npm i -D @vue/babel-preset-app
//babel.config.js
module.exports = {
presets: [
'@vue/app'
]
};
babel.config.js
module.exports = {
plugins: [
[
"import",
{ libraryName: "ant-design-vue", libraryDirectory: "es", style: true }
],
"@babel/plugin-syntax-dynamic-import"
]
}
npm i -D @vue/babel-preset-app
//babel.config.js
module.exports = {
presets: [
'@vue/app'
]
};