vue自动化单元测试

 1 // 引用vue和需要测试的组件
 2 import Vue from 'vue'
 3 import HelloWorld from '@/components/HelloWorld'
 4 // 创建测试套件,一个测试组件写一个测试套件
 5 describe('HelloWorld.vue', () => {
 6   // 测试用例,用来测试不同的方法或者显示的内容
 7   it('should render correct contents', () => {
 8     const Constructor = Vue.extend(HelloWorld)
 9     const vm = new Constructor().$mount()
10     // 判断页面中是否有msg所渲染出来的内容
11     // 等价document.querySelector('.hello h1')
12     expect(vm.$el.querySelector('.hello h1').textContent)
13       .to.equal('Welcome to Your Vue.js App')
14   })
15 })

猜你喜欢

转载自www.cnblogs.com/yangguoe/p/9394838.html