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

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

  •  
  •   DongZhe93 · 2019-12-12 20:31:21 +08:00 · 2411 次点击
    这是一个创建于 1793 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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  
       2020-02-25 10:06:24 +08:00
    楼主找到解决方案了吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2807 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 81ms · UTC 02:01 · PVG 10:01 · LAX 18:01 · JFK 21:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.