This document covers unit testing for the tackle2-ui client. For end-to-end (E2E) testing with Cypress, see cypress/README.md.
- Jest will assume everything in directories named
__test__will be related to tests. - Our thought process around test selectors is generally to decouple display logic from any testing logic. This involves following the
testing-libraryrecommendation for selecting elements based on role instead of creating test specific IDs where possible. Docs on selector priority here.- NOTE: the above applies to our testing methodology for our unit tests. For QE automation tests, we should be providing an
idfor each form field. Other than form fields, we are assuming that QE can usePatternflyprovidedidselectors where possible. We plan to handle any issues relating to a missingidon a case-by-case basis.
- NOTE: the above applies to our testing methodology for our unit tests. For QE automation tests, we should be providing an
- We are using js-dom (fake dom implementation) for the testing library. Configured in
jest.config.js.
- We use the jest functions
describeanditfor organizing our test files. These functions are used to create groups of related tests. Docs here.
- To run a single test, run:
npm run test -w client -t 'test name here'
- To run entire test suite, run:
npm run test -w client
- To update snapshot tests, run:
npm run test -w client -- -u
- To run tests in
watchmode to aid in writing tests, run:
npm run test -w client -- --watch