Skip to content
Learn Netverks

Lesson

Step 30/36 83% through track

testing-intro

Testing introduction

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
intermediate

This lesson

An orientation to the Node.js track—how the server playground works, core vocabulary, and what you will practice next.

You need a clear map of the Node.js track so the event loop, modules, and server runtime do not feel like magic.

You will apply Testing introduction in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons. Also read the interview prep blocks.

After HTML fundamentals and basic programming concepts—before or alongside SQL.

Tests protect refactors and document behavior. Node ships a built-in test runner (node --test); Jest and Vitest are popular alternatives with mocking utilities.

Test pyramid

  • Unit — pure functions, validators, utils (fast, many)
  • Integration — HTTP handlers with supertest, DB test containers
  • E2E — full browser/API flows (fewer, slower)

node:test sketch

import { test } from 'node:test';
import assert from 'node:assert/strict';

test('adds numbers', () => {
  assert.equal(1 + 2, 3);
});

What to test first

Validation functions, auth guards, and business rules before UI—high value, low setup. Mock external APIs at HTTP boundary.

Important interview questions and answers

  1. Q: Unit vs integration test?
    A: Unit isolates one module; integration exercises real HTTP/DB layers together—slower but catches wiring bugs.
  2. Q: How test Express routes?
    A: supertest calls app without listening on a port—assert status and JSON body.

Self-check

  1. What command runs Node built-in tests?
  2. Why test validators before controllers?

Tip: Test pure functions first—they need no HTTP mock and give fast feedback before integration tests.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Unit vs integration?
  • Mock fetch when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump