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() ...

Get Vue.js 2 and Bootstrap 4 Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.