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?
- AJest retries failed promises until they pass
- Bexpect() does not work inside .then callbacks
- CtoBe cannot compare booleans
- 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