Your First Test
To illustrate how quick and easy it is to get started with automated unit tests in a Vue CLI project, we will start by setting up and writing a unit test with Jest, @vue-test-utils
. There is an official Vue CLI package that can be used to generate a setup that includes unit testing with Jest and vue-test-utils
. The following command should be run in a project that has been set up with Vue CLI:
vue add @vue/unit-jest
Vue CLI adds Jest as the test runner, @vue/test-utils
, the official Vue.js
testing utilities, and vue-jest
, a processor for .vue
single-file component files in Jest. It adds a test:unit
script.
By default, it creates a tests/unit
folder, which we'll remove. Instead, we can create a __tests__
folder and create an App.test.js
file as follows.
We will use shallowMount
to render the application and test that it displays the correct text. For the purposes of this example, we'll use the text: "The Vue.js Workshop Blog
".
shallowMount...