Unit tests verify individual functions or components in isolation.
1. Getting Started
What is Node.js?
2. Modules & NPM
Modules & NPM
9. Process & Environment
Process & Environment Variables
10. Caching & Performance
Redis Caching
11. GraphQL with Node.js
GraphQL Basics
Syntax
NODEJS
const assert = require('assert'); function add(a, b) { return a + b; } assert.strictEqual(add(1, 2), 3); assert.strictEqual(add(-1, 1), 0);
Unit Testing with Jest
NODE
// math.js function add(a, b) { return a + b; } function divide(a, b) { if (b === 0) throw new Error("Cannot divide by zero"); return a / b; } // math.test.js // describe("Math", () => { // test("add", () => { // expect(add(2, 3)).toBe(5); // }); // test("divide", () => { // expect(divide(10, 2)).toBe(5); // }); // test("divide by zero", () => { // expect(() => divide(1, 0)).toThrow(); // }); // });
Up next
Debugging with Node
Lesson 12 of 17 · Testing & Debugging