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)
1
jiaoguibin 2020-02-25 10:06:24 +08:00
楼主找到解决方案了吗
|