How it works...

You wrote your very first unit test for a Vue application. If you write unit tests already, everything should be quite clear since we have not used any feature unique to Vue to write the test.

In any case, let's spend a little time analyzing the code we have written; after that, I'll provide some considerations about when you should write similar tests when writing a real application.

The test we wrote displays my app should say Hello World when you read it as a sentence on the web page.

This is a fairly generic message; however, let's look at the code closely:

expect(document.querySelector('p').innerText)  .toContain('Hello World')

Read it as an English phrase--we expect the <p> element inside the document to contain the ...

Get Vue.js 2 Cookbook 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.