使用Vue Test Utils,生成了wrapper,调用wrapper.vm.getCtModal(),因为使用ts语言,所以编译器会报出找不到xxxmethod的类型声明,问应该要怎么让xxxmethod有类型声明,或者使用其他方式调用vue实例的方法?
使用vue cli 3 创建的项目,使用官方推荐的@vue/test-utils工具书写单元测试,单元测试使用typescript语言,mocha测试框架以及chai断言库
// 请把代码文本粘贴到下方(请勿用图片代替代码)
import { expect } from 'chai';import { shallowMount } from '@vue/test-utils';import Toast from '@/components/toast/Toast.vue'; describe('Toast.vue', () => { it('测试tips的值', (done) => { const tips = '请再靠近一点'; const wrapper = shallowMount(Toast); wrapper.vm.getCtModal('notLoginError'); wrapper.vm.$nextTick(() => { const div = wrapper.find('.loading-title'); expect(div.text()).to.equal('尚未登录,请先登录'); done(); }); }); });
牧羊人nacy
相关分类