Files
2025-08-27 05:39:11 -07:00

31 lines
1.3 KiB
Plaintext

---
description: Creating unit tests
globs:
---
# Creating unit tests
- This project uses `vitest` for unit testing
- Do not build custom testing infrastructure; use Vitest and existing helpers
- Tests are stored in the `tests/unit/` directory
- Directory structure of `tests/unit/` should match that of the tested file in `src/`
- Tests should be cross-platform compatible; able to run on Windows, macOS, and linux
- e.g. the use of `path.normalize`, or `path.join` and `path.sep` to ensure that tests work the same on all platforms
- vitest automatically runs the setup file [setup.ts](mdc:tests/unit/setup.ts) before running each test file
- Tests should be mocked properly
- Mocks should be cleanly written and easy to understand
- Mocks should be re-usable where possible
- Read at least five existing unit tests to determine testing patterns
- [appState.test.ts](mdc:tests/unit/main-process/appState.test.ts) is a good example
- [desktopApp.test.ts](mdc:tests/unit/desktopApp.test.ts) is a good example
## Unit test style
- Prefer the use of `test.extend` over loose variables
- To achieve this, import `test as baseTest` from `vitest`
- Never use `it`; `test` should be used in place of this
## Pre-commit checks (tests)
- Run `yarn test:unit` before committing changes