JavaScript theorytheory 0/50 · 0%
Tooling · hard

44. Testing JavaScript

Unit tests, mocks and async assertions.

A test arranges, acts and asserts. Network calls are mocked so tests stay deterministic; async tests must await the work before asserting.

test("formats wei", () => {
  expect(format(1500000000000000000n)).toBe("1.5");
});

Test behaviour, not implementation details — tests coupled to internals break on every refactor.

Check your understanding

  1. 1. Why mock network calls?

  2. 2. What must an async test do?

  3. 3. What should tests target?