Node.js · 14-day planAll days
Day 13 of 14 30 minnode:testassertMocks
Write automated tests with Node's built-in test runner and assert module. Structure tests with describe and it, use hooks for setup, test async code and error cases, replace dependencies with mocks, test an HTTP API end to end, and run tests in watch mode and CI.
By the end of today you can
- Write tests with node:test and node:assert/strict
- Organise tests with describe, it and hooks
- Test async functions and expected errors
- Replace dependencies with mock functions
- Test an HTTP API by starting it and calling it with fetch
What's inside
- 6 sections
- 2 diagrams and mind maps
- 4 code examples you can run
- 5-question quiz
- 1Your first tests
- 2Assertions
- 3describe, hooks and async code
- 4Mocks: replacing dependencies
- 5Testing an HTTP API
- 6Running tests on your computer
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free