A small learning project for mastering Jest with TypeScript.
This repository is designed to help you practice and learn Jest testing in a TypeScript environment. It includes a simple source file and a test suite configured to run with ts-jest.
- Install dependencies:
pnpm install- Run the test suite:
pnpm test- Learn Jest test structure:
describe,test, andexpect - Write simple unit tests for functions and return values
- Run Jest tests locally with
pnpm test - Use matchers like
toBe,toEqual,toContain, andtoHaveLength
- Test asynchronous code with
async/await,resolves, andrejects - Mock functions and modules using
jest.fn()andjest.mock() - Use setup and teardown hooks:
beforeEach,afterEach,beforeAll,afterAll - Organize test files and improve coverage with targeted cases
- Explore spies, deep mocks, and custom matchers
- Test Express routes or API handlers in Node.js
- Use snapshot testing for component or object output validation
- Configure Jest with TypeScript via
ts-jestand custom transformer settings
- Write resilient tests that focus on behavior, not implementation
- Combine Jest with code coverage reports and continuous integration
- Use advanced mock behaviors for complex dependencies
- Debug failing tests and maintain a clean, stable test suite