【发布时间】:2021-10-25 18:26:46
【问题描述】:
我已经安装了 Vue 测试工具,安装了 Jest 并有一个测试用例来验证 vue 实例是否有效。
我的测试如下所示
/* global describe, test, expect */
/* eslint no-undef: "error" */
import { mount } from '@vue/test-utils';
import Logo from '@/components/Logo';
describe('Logo', ()=> {
test('is a vue instance', () => {
const wrapper = mount(Logo)
expect(wrapper.vm).toBeTruthy()
});
});
我使用npm run test 运行它并得到以下错误
import { mount } from '@vue/test-utils'
Syntax error: Unexpected token {
(with an carrot pointing to the { in front of { mount }
有什么想法吗?
***** 编辑添加我的 jest.config.js ****
module.exports = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
'^~/(.*)$': '<rootDir>/$1',
'^vue$': 'vue/dist/vue.common.js'
},
moduleFileExtentions: ['js', 'vue', 'json'],
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
transform: {
'^.+\\.js$' : 'babel-jest',
'.*\\.(vue)$' : 'vue-jest'
},
collectCoverage: true,
collectCoverageFrom: [
'<rootDir>/components/**/*.vue',
'<rootDir>/pages/**/*.vue'
]
}
【问题讨论】:
-
你能从你的 package.json 中发布脚本“test”吗?
-
确定只是“测试”:“开玩笑”
-
试试:
"test": "vue-cli-service test:unit" -
我编辑添加我的 jest.config.js 上面运行该命令给了我 sh: vue-cli-service: command not found 如果我在做 NuxtJs,我需要添加什么吗?跨度>
标签: vue.js jestjs nuxt.js vue-test-utils