账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    element ui 使用@vue/test-utils测试,无法触发button
    • 2020-01-01 00:00
    • 11
    51
    0

    vue

    <template>
      <div class="hello">
        // 这种方式不行
        <el-button type="primary" @click="add()" id="add">新增</el-button>
        // 这种方式可以通过测试
        <div id="add"  @click="add()"></div>
      </div>
    </template>
    
    <script>
    export default {
      name: 'HelloWorld',
      data() {
        return {
          count: 0
        }
      },
      methods: {
        add() {
          this.count++
          console.log(this.count);
        }
      }
    }
    </script>

    test

    import { shallowMount, createLocalVue } from '@vue/test-utils'
    import HelloWorld from '../../src/views/HelloWorld.vue'
    import ElementUI from 'element-ui';
    
    const localVue = createLocalVue();
    localVue.use(ElementUI);
    
    describe('HelloWorld.vue', () => {
      it('测试count组件能否正常显示并增加', () => {
        const wrapper = shallowMount(HelloWorld, {localVue})
        expect(wrapper.vm.count).toBe(0)
        wrapper.find('#add').trigger('click')
        expect(wrapper.vm.count).toBe(1)
        
      })
    })

    用element ui 的就不能通过测试,没有触发btn

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 陌路离殇 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部