Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Frontend Testing

Unit Tests

  • Unit tests are colocated with the code they test. Good examples of test files can be found in the /apps/app/src/utils/__tests__ directory, which contains unit tests for the files in the /apps/app/src/utils/ folder.
  • Additional examples of unit test files exist throughout the frontend codebase. They have a .test.{ts,tsx} extension and are sometimes located in __tests__ directories.

Unit Test Approach

  • Implemented using vitest
  • Add as many unit tests as possible, especially for pure functions and complex business logic that can be tested independently without relying on extensive mocking and external dependencies.
  • Prioritize testing different properties and scenarios to catch hard-to-miss edge cases instead of only following the happy path with a few examples.

Running Unit Tests

  • Run pnpm test:unit to run all unit tests
  • Run pnpm test:unit:coverage to run all unit tests and get a coverage report in the terminal