Skip to content
Chapter 86Lesson 5

Quiz - The shape of a test suite

Quiz progress

0 / 0

Your project is ESM and TypeScript top to bottom. What is the load-bearing reason the course picks Vitest over Jest for it?

Vitest runs .ts and .tsx through the Vite + TypeScript pipeline the project already has, so there’s no second ts-jest/Babel transform to configure and keep in sync.
Vitest’s describe / it / expect API is more powerful than Jest’s, so tests can assert things Jest can’t.
Vitest runs every test file in parallel while Jest runs them one at a time, so the suite is always faster.

A teammate argues your suite “isn’t a real honeycomb” because it has 200 unit tests and only 80 integration tests — integration should be the largest band. How should you respond?

The honeycomb names where each test lives, not how many of each — band weights follow the codebase, so 200 unit / 80 integration can be a perfectly healthy honeycomb.
They’re right — to be a honeycomb the integration count must exceed the unit count, so you should add integration tests until it does.
They’re right that the counts are wrong, but the fix is deleting unit tests until integration is the majority, not adding more tests.

You want coverage to flag files in /lib that have no test at all — right now they vanish from the report instead of showing up as a problem. On the project’s Vitest 4 setup, what surfaces them?

Set coverage.include to globs over your load-bearing surface (e.g. src/lib/**/*.ts); files matched but never imported then appear at 0% instead of disappearing.
Set coverage.all: true so every source file is pulled into the report at 0% coverage.
Raise the /lib threshold to 100% so the missing files fail the build.

To test that safeLimit fails open when Redis is unreachable, a developer writes vi.spyOn on the limiter to reject, calls safeLimit, then asserts expect(spy).toHaveBeenCalledWith('ip:1.2.3.4'). Why is this the wrong assertion?

It asserts the mock was called with the key the test itself wired in — verifying the function’s internal plumbing, not the fail-open decision the caller acts on; assert the returned result ({ success: true }) instead.
Using vi.spyOn at all is the mistake — you should never mock a dependency, even to arrange a failure you can’t trigger for real.
toHaveBeenCalledWith is too strict a matcher; switching to toHaveBeenCalled would make the test correct.

Quiz complete

Score by topic