(JEST / VueJS)无法在模块外部使用import语句

时间:2020-04-16 09:25:40

标签: vue.js jestjs windows-10 nuxt.js

我正在使用Windows10,当我在VUEJS项目上运行Jest进行测试时,我已经得到了:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { shallowMount } from '@vue/test-utils';
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1086:14)

迭代了很多解决方案,但仍然无法正常工作这是我的jest.config.js文件:

module.exports = {
    moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
    transform: {
        "^.+\\.js$": "babel-jest",
        ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
    },
    moduleNameMapper: {
        "^.+.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
    },
    snapshotSerializers: [
        "<rootDir>/node_modules/jest-serializer-vue"
    ],
    testMatch: [
        '<rootDir>/tests/**/*.spec.(js|jsx|ts|tsx)|<rootDir>/**/__tests__/*.(js|jsx|ts|tsx)'
    ],
    transformIgnorePatterns: ['<rootDir>/node_modules/']
};

0 个答案:

没有答案
相关问题