Testing
We love tests. And test everything we can. In this section, we will discuss two types of tests and describe our toolset.
Everything comes configured, so you can just start using it. Run
npm run test
to run everything we have.We have two types of test: unit and end-to-end. They differ in complexity, tools, and reasoning.
Unit tests are considered much easier to write, but harder to maintain. Because they are simple and there should be a lot of them.
Use
npm run test:unit
to run unit tests.We use
jest
snapshots to be sure that our components rendering did not change without notice. It saved us million times!// An example from 'tests/unit/pages/index.spec.js':
const wrapper = mount(Index, { store, localVue, propsData })
expect(wrapper.html()).toMatchSnapshot()
These two lines will create fake
Index
component, mount it to the page, then render it to string, and serialize to the text file inside __snapshots__
folder near the test itself. There can be multiple snapshots for different component states.Run
npm run test:unit -u
to update existing snapshots with the updated state.Unit tests should not go into the wild and request data. We leave this controversial topic to you.
However, we are using
axios-mock-adapter
to illustrate the point. You are free to use any kind of mocks you want.We can use different assets and static files like fonts, images,
svg
icons. At some point jest
might fail to load and transform them.So, we provide
jest-svg-transformer
and jest-transform-stub
that will help you in this field.jest-svg-transformer
will loadsvg
as fake componentjest-transform-stub
will just stub all static files with no-ops
We also run security checks on each CI step. We use
npm audit
to fail your CI when bad packages are found.This way you can lower the risks.
Last modified 3yr ago