Chapter 12. Testing
This chapter covers
- Understanding why we test
- Implementing unit tests
- Testing components
- Testing Vuex
We’ve discussed many important topics in this book, but one often-neglected topic doesn’t get enough attention: testing. Testing is an extremely important aspect in any software development project. It ensures that the app behaves the way we expect it to—without bugs. In this chapter, we’ll discuss why you should create tests for your application. Then we’ll look at the fundamentals of unit testing. Next, we’ll look at component testing, both the output and the methods. Finally, we’ll see how to get started testing with Vuex.
It’s worth mentioning before we start that testing is a huge subject. In this chapter, I’ll cover several of the most important aspects of testing with Vue.js. I strongly recommend you look over Edd Yerburgh’s Testing Vue.js Applications (Manning, 2018). In his book, Edd delves into much more detail on creating and developing tests. He also covers server-side rendering testing, snapshot testing, and testing mixins and filters.
Snapshot testing
Snapshot tests are useful tools when you want to ensure that the UI doesn’t change unexpectedly. In this chapter, I’ll use mocha-webpack, which doesn’t support snapshot testing as of this writing. However, if you want to learn more about snapshot testing, look over the official guides for more information on how to set up Jest with snapshot testing at http://mng.bz/1Rur.