Snapshot testing with Jest
One of the coolest features of Jest is snapshot testing. What is snapshot testing? When our components are being rendered, they produce some HTML markup, right? It would be really important that once your application is stable, none of the newly added functionality breaks the already existing stable markup, don't you think? That's why snapshot testing exists. Once you generate a snapshot for some component, it will persist in the snapshot folder and on each test run, it will compare the output with the existing snapshot. Creating a snapshot is really easy. After you mount your component, you should just call the expectation toMatchSnapshot
on this component's HTML:
let $html = $mounted.$el.outerHTML
expect($html).toMatchSnapshot()
I will run snapshot testing for all the pages inside one test suite file. Before doing that, I will mock the getters of our Vuex store because there are some pages that use the user object, which is not initialized, thus resulting in an...