我已经开始尝试用jest为vue.js项目编写单元测试。我尝试过的所有其他功能都可以运行,除了在构建项目时允许使用一些import语句。
我尝试弄乱babel,jest,babel-jest和项目的配置文件,但是无论我尝试什么更改,它仍然会给我同样的错误。
示例单元测试失败:
import { mount } from '@vue/test-utils'
import EventShow from '@/views/EventShow.vue'
describe('EventShow', () => {
test('Simple Test', () => {
expect(3).toBe(3)
})
test('is a Vue instance', () => {
const wrapper = mount(EventShow)
expect(wrapper.isVueInstance()).toBeTruthy
})
})
错误消息:
> jest __tests__
FAIL src/views/__tests__/TestEventShow.test.js
● Test suite failed to run
Cannot find module '@/components/EventShow.vue' from 'TestEventShow.test.js'
1 | import { mount } from '@vue/test-utils'
> 2 | import EventShow from '@/components/EventShow.vue'
| ^
3 |
4 | describe('EventShow', () => {
5 | test('Simple Test', () => {
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:230:17)
at Object.<anonymous> (src/views/__tests__/TestEventShow.test.js:2:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.439s
Ran all test suites matching /__tests__/i.