CodingNic

Testing Fundamentals with Jest

Module Overview

Testing Fundamentals with Jest 5 min read

Module Overview

What You’ll Learn

  • Write and run unit tests with Jest
  • Use assertions to check a function’s behavior, including error cases
  • Mock a dependency so a unit test doesn’t depend on a real database

💡 Why this matters: Every module so far has been verified by hand, running a script, reading the output. Jest automates exactly that, and keeps doing it every time the code changes, catching a broken password check or a broken validation rule before it ships.

What’s Covered

  • Writing a test, describe, it/test, and assertions with expect.
  • Testing pure functions, application logic with no side effects.
  • Testing error cases, confirming a function throws or rejects when it should.
  • Mocking, replacing a real dependency (a database call) with a fake one for a unit test.

Hands-On

By the end of this module, you’ll have a real Jest test suite covering this course’s password-hashing and validation logic, run with a single command.

Next module: integration testing, running real HTTP requests against a real Express app.