Course lesson 58 · Wrapping Up

Writing Tests

One study unit · Read, recall, then practice · Original video 00:14:52

The testing section demonstrates unit tests around business logic, using mocks to isolate database calls, workflow scheduling, and Durable Object dependencies. Queue-handler tests check forwarded data, operation order, and error behavior. Tracker tests cover alarm creation, avoiding duplicate alarms, broadcasting a batch to multiple clients, advancing offsets, and deleting older clicks.

Primary source: course video 58 · Supplied English subtitles · 00:14:52.

Understand the idea

What the course does

  1. Mock click persistence and workflow scheduling in the queue-handler tests and reset mocks between cases.
  2. Pass a representative click event and check that the expected data reaches persistence.
  3. Verify that persistence precedes workflow scheduling, and that a simulated database error prevents dependent work.
  4. Construct mocked Durable Object storage, SQL, and socket dependencies for tracker tests.
  5. Test the no-alarm and existing-alarm branches of adding a click.
  6. Trigger an alarm with a prepared batch and two sockets, then assert delivery, offset updates, and cleanup.

Watch for

Recall before revealing

What can a mocked tracker test prove, and what can it not prove?

Reveal the explanation

It can check the application’s decisions and calls for controlled inputs; it cannot prove that the real Cloudflare runtime behaves exactly like those mocks.

Try it

Design one meaningful failure-path test for the tracker or queue handler and state the behavior it protects.

Check your result

Your test links a realistic failure to an explicit business requirement, rather than merely repeating the implementation’s call sequence.

Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.

Rewatch only what you need

Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.

Companion primary documentation: Cloudflare Workers Vitest integration. For recorded API names, commands, limits, and prices, check the version you use.

← Previous   Next →