Automated Testing in JavaScript: From the First Assert to CI
Automated Testing is an intermediate-level course of 5 lessons (about 2 h 54 min), with 15 exercises and 15 quiz questions. Prerequisites: Data Structures and Complexity. Exercises run in the browser, with nothing to install.
- Back-end
- Intermediate
- 5 lessons
- 2 h 54 min
- 15 exercises
- Exercises run in the browser
The course in brief
This course teaches you to secure your code with automated tests. You will start with node:assert assertions and the built-in node:test runner, then test asynchronous code with test doubles, practice TDD, discover Jest and Vitest, and finish with integration tests, coverage, and continuous integration.
What you will be able to do
- Write correct assertions with node:assert and choose relevant test cases
- Organize a readable, independent test suite with node:test
- Test asynchronous code and isolate dependencies with stubs, spies, and fakes
- Apply the TDD cycle and use the expect API of Jest and Vitest
- Test middleware and HTTP routes, interpret coverage, and configure CI
Syllabus: 5 lessons
- Explain what an automated test brings and place the levels of the test pyramid
- Write assertions with node:assert (strictEqual, deepStrictEqual, throws)
- Choose relevant test cases, including edge cases
- 02
Node's Test Runner: Organizing Your Tests
- Write and run tests with node:test and node --test
- Structure a test using the Arrange-Act-Assert pattern
- Keep tests independent with beforeEach/afterEach hooks
- 03
Async Tests and Test Doubles (Mocks, Stubs, Spies)
- Test asynchronous functions with async/await and assert.rejects
- Replace a dependency with a test double (stub, spy, fake)
- Make code testable through dependency injection
- 04
TDD and Test Frameworks: Jest and Vitest
- Apply the red-green-refactor TDD cycle on a small feature
- Read and write tests with the expect API of Jest and Vitest
- Choose between node:test, Jest, and Vitest depending on the project
- 05
Integration Tests, Coverage, and Continuous Integration
- Test a middleware or an HTTP route with fake objects and with real requests
- Interpret a code coverage report
- Automate tests in a continuous integration pipeline
Final project
Cover a Task Management API with Tests
You receive a small Node.js API (creating, listing, modifying, and deleting tasks, with API-key authentication) that has no tests at all. Write a complete suite: unit tests of the validation functions and middleware, service tests with test doubles, HTTP integration tests of each route, then configure coverage and a CI workflow. A regression bug is reported to you: fix it with TDD.
Deliverables
- The test files (node:test or Vitest) organized by module
- A non-regression test written before fixing the reported bug
- The coverage report and a short analysis of the uncovered areas
- A CI workflow file that runs the tests on every push
Assessment criteria
- The tests pass, are independent, and are deterministic
- Nominal, edge, and error cases are covered for each route
- Test doubles are used appropriately (external boundaries only)
- Test names clearly describe the behaviors
- CI does fail when a test is deliberately broken
Frequently asked questions
Do I need to know Jest to take this course?
No. The course starts with the tools built into Node.js (node:assert and node:test), then presents Jest and Vitest, whose API is very similar.
What is the difference between a unit test and an integration test?
A unit test checks an isolated function, replacing its dependencies. An integration test checks that several parts work together, for example an HTTP route with its database.
Jest or Vitest: which should I choose?
Vitest is often preferred for Vite, ESM, and TypeScript projects; Jest remains very present in existing projects. The concepts are identical and the course compares the two.
Is TDD mandatory?
No, but it is an effective method for clarifying a business rule or fixing a bug. The course has you practice it on short examples.
This course, told for your job
Say what you want to be able to do: “Automated Testing” takes its place in your path, with examples from your field. The concepts stay those of the course.