codejump

Mocks, Spies & Integration

Preview — 3 of 10 questions

What do beforeEach and afterEach do in test frameworks?

ARun before and after all tests in a suite.
BRun before and after each individual test.
CAre aliases for setUp and tearDown.
DAre only used in end-to-end tests.

How do you test an async function?

ATest functions must be synchronous.
BReturn a Promise or use async/await.
CUse done callback only.
DAsync functions cannot be tested.

How do you test that a function throws an error?

ALet the error happen naturally.
BTry/catch around the function.
CUse expect(...).toThrow() or expect(...).rejects.toThrow().
DErrors cannot be tested.

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.