JavaScript & TypeScript / Quiz

Promises Under Test: Return or Regret

resolves, rejects, forgotten returns, and the done callback that Jest tolerates and Vitest killed. Async assertions that actually assert.

Difficulty
Easy
Format
Quiz
Points
100
Estimate
8 min

// MISSION BRIEF

Your Mission

The most dangerous async test is a green one. Forget a single await and your assertions run after the test already passed, cheerfully reporting success on a broken function.

This quiz covers the mechanics Jest and Vitest give you for promises: returning them, awaiting them, .resolves / .rejects, expect.assertions, and the legacy done callback.

Speed bonus active.

// FIRST CONTACT

Battle teaser

test('saves', () => { save().then(r => expect(r.ok).toBe(true)); }) passes even when r.ok is false. Why?

  1. AJest retries failed promises until they pass
  2. Bexpect() does not work inside .then callbacks
  3. CtoBe cannot compare booleans
  4. DThe promise is neither returned nor awaited, so the test completes before the .then callback runs; the failing assertion lands after the verdict
Answers, scoring, hints, and the full battle stay sealed.

// SKILL TAGS

javascriptasyncpromisesjestunit-testing