У меня в проекте vuejs тест страницы входа с тестовым шутом:
import Vuex from "vuex";
import { shallowMount, createLocalVue } from "@vue/test-utils";
import LoginForm from "@/components/LoginForm.vue";
import store from "@/store";
const localVue = createLocalVue();
localVue.use(Vuex);
describe("LoginForm.vue", () => {
it("input id and password exist", () => {
const wrapper = shallowMount(LoginForm, {
mocks: {
$t: () => {}
},
store,
localVue
});
//const div = wrapper.find("el-input");
expect(wrapper.find("#inputId").exists()).toBeTruthy();
expect(wrapper.find("#inputPassword").exists()).toBeTruthy();
});
});
и lauch it by run test:unit-coverage
(в пакете json: "test:unit-coverage": "jest --clearCache && vue-cli-service test:unit --coverage"
)
Это было хорошо, пока в проекте не было добавлено ag-grid- vue ...
Теперь у меня ошибка
FAIL tests/unit/specs/login.spec.js
● Test suite failed to run
C:\DevSources\node_modules\ag-grid-vue\lib\AgGridVue.js:20
import { Component, Prop, Vue } from 'vue-property-decorator';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (node_modules/ag-grid-vue/main.js:6:10)
Я пытался изменить конфигурацию, но ошибка уже присутствует
jest.config. js:
module.exports = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "vue"],
transform: {
"^.+\\.vue$": "vue-jest",
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$":
"jest-transform-stub",
"^.+\\.jsx?$": "babel-jest"
},
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1"
},
snapshotSerializers: ["jest-serializer-vue"],
testMatch: [
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
],
testURL: "http://localhost/"
};
babel.config. js:
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"]
};
Спасибо за помощь.