Agent Wranglers

Test quality Required

Make every test able to fail

Every test must contain a check that fails when the behaviour breaks. Tests without assertions or with always-true checks are not tests.

How to do it

Watch each new test fail once before making it pass. Turn on lint rules that catch empty or assertion-free tests, such as vitest/expect-expect or jest/expect-expect. Await every asynchronous assertion.

Example

// Bad: passes even when createUser is broken, because nothing is checked
test('creates a user', async () => { await createUser('ada@example.com'); });

// Good: fails when the user is not stored
test('creates a user', async () => {
  await createUser('ada@example.com');
  expect(await findUser('ada@example.com')).toMatchObject({ email: 'ada@example.com' });
});

How to check

The linter reports no test without an assertion. Breaking the code under a new test turns it red.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/test-quality/tests-can-fail.