Unit testing
All new code that is added to vets-website
should be unit tested and unit tests should cover at least 75% of code paths. Write unit tests as you build to make sure your form (or other component) is behaving as you expect and to help guard against future bugs.
Unit test file format: file_name.unit.spec.js
Where: Any file_name.unit.spec.js file located in the /src
folder. This file is usually located in a test directory close to the code being tested.
When: Run the test locally through npm script commands, during the Jenkins build (Unit), and after merging to main.
How: Write a unit test.
Libraries used:
- mocha.js: Test framework.
- chai.js: BDD / TDD assertion library.
- chai-as-promised: Extends Chai with assertions about promises.
- sinon.js: Standalone test spies, stubs and mocks.
- enzyme: Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output. You can also manipulate, traverse, and in some ways simulate runtime given the output.
- enzyme-adapter-react-16: Enzyme React 16 integration.
- react-dom: React DOM Library needed for testing React Components.
- react-dom/test-utils: Test utilities for React DOM.
- react-test-renderer: This package provides an experimental React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.
- jsdom: A JavaScript implementation of the WHATWG DOM and HTML standards, for use with node.js.
- mocha-junit-reporter: Produces JUnit-style XML test results. This is used specifically for Jenkins so it can output and track test results in its system.
- choma: Random execution order for mocha suites.