Jest 单元测试 Vue 项目中引入的 mint-ui 报错
import {createLocalVue, mount} from '@vue/test-utils'
import inputCheckData from '@/pages/health/inputCheckData'
import MintUI from 'mint-ui';
const localVue = createLocalVue()
localVue.use(MintUI)
describe('health/inputCheckData.vue', () => {
it('check query', () => {
const $route = {
query: {
id: 1
}
}
const wrapper = mount(inputCheckData, {
localVue,
mocks: {
$route
}
})
expect(wrapper.vm.$route.query.id).toBe(1)
expect(wrapper.vm.$data.type).toBe(1)
})
})
Test suite failed to run
TypeError: Cannot read property 'toLowerCase' of undefined
> 1 | import {createLocalVue, mount} from '@vue/test-utils'
2 | import inputCheckData from '@/pages/health/inputCheckData'
3 | import MintUI from 'mint-ui';
4 |
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:3:197)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:2:2834)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:3:19753)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:2:9215)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:3:19848)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:1:6914)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:1:8192)
at e (node_modules/mint-ui/lib/index.js:1:447)
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:4:12126)
at e (node_modules/mint-ui/lib/index.js:1:447)
at node_modules/mint-ui/lib/index.js:1:830
at node_modules/mint-ui/lib/index.js:1:841
at node_modules/mint-ui/lib/index.js:1:170
at Object.<anonymous> (node_modules/mint-ui/lib/index.js:1:323)
at Object.<anonymous> (test/unit/health/inputCheckData.test.js:1:114)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.