教你如何编写Vue.js的单元测试的方法

2020-06-16 06:11:26易采站长站整理

// set input value
ListComponent.setData({
newItem: 'brush my teeth',
});

// simulate click event
const button = ListComponent.find('button')[0];
button.dispatch('click');

// assert list contains new item
expect(ListComponent.text()).to.contain('brush my teeth');
expect(ListComponent.data().listItems).to.contain('brush my teeth');
})
})

总结

我个人认为写作测试对于我的正常工作流程至关重要,但是使用JavaScript,特别是VueJS,我开始碰到一些麻烦。希望本教程将帮助任何与我一样遇到麻烦的人!

本文中的所有代码可以在 Github 下载。