EduFlow
Testing JavaScript Apps

Checkpoint: Unit Tests That Matter

Five questions on this section. Answer all of them, then see your score and why each answer is right or wrong.

Question 1 of 5

Splitwise-lite gives free premium to groups that spend $50.00 (5000 cents) or more. Which two inputs best test the rule?

Question 2 of 5

What should change in this test?

JavaScript
test('rejects a negative amount', async () => {
  expect(saveExpense({ description: 'Taxi', amountCents: -100 }, api))
    .rejects.toThrow('positive');
});
Question 3 of 5

While testing computeBalances, a test replaces splitEvenly with vi.fn().mockReturnValue([500, 500]). Later splitEvenly gets a rounding bug. What happens to that test?

Question 4 of 5

The second row of this table fails. What test name does Vitest report?

JavaScript
test.each([
  { total: 1000, people: 3, first: 334 },
  { total: 1001, people: 4, first: 251 },
])('splits $total between $people', ({ total, people, first }) => {
  expect(splitEvenly(total, people)[0]).toBe(first);
});
Question 5 of 5

A reminder is scheduled with setTimeout to go out 24 hours after an expense is added. With vi.useFakeTimers() active, which line makes the reminder fire in the test?

5 questions unanswered