首页   注册   登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
DongZhe93
V2EX  ›  Vue.js

Jest 单元测试 Vue 项目中引入的 mint-ui 报错

  •  1
     
  •   DongZhe93 · 78 天前 · 1139 次点击
    这是一个创建于 78 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 回复  |  直到 2020-02-25 10:06:24 +08:00
    jiaoguibin
        1
    jiaoguibin   4 天前
    楼主找到解决方案了吗
    关于   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   2991 人在线   最高记录 5168   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 03:14 · PVG 11:14 · LAX 19:14 · JFK 22:14
    ♥ Do have faith in what you're doing.