Integration test a Vue component with vue-testing-library

Share this video with your friends

Send Tweet

In this lesson, we'll use vue-testing-library along with Jest to write some integration tests for a Counter component. What's nice about the vue-testing-library and it's equivalents like dom-testing-library and react-testing-library is that it has several functions to retrieve and assert on elements like a user would when interacting with your application.

When a user clicks a button, they're not clicking on a CSS class (as some testing libraries suggest), they're clicking on a button labeled "Increment". The user doesn't know about the implementation details, so testing an app this way makes sense. We'll look at several of the getBy* functions vue-testing-library offers to test our component.

Additional Resources:

https://blog.kentcdodds.com/introducing-the-react-testing-library-e3a274307e65?gi=2b3d25b4f1cd

https://github.com/dfcook/vue-testing-library