Skip to content

No Assertions in Test

Error message

                Test has no assertions — expected at least one assertion
              

Quick summary

The test completed without calling expect(). Without assertions, the test always passes — even if the code is completely broken.

Why this happens

  • The test calls a function but never checks the result with expect().

  • Assertions are inside a conditional block that doesn't execute.

  • Assertions are inside an async callback that never runs.

  • The test was written as a smoke test (just 'does it run?') without verifying output.

Minimal example

✗ Broken code
test('add', () => {
  const result = add(2, 3);
  // no assertion — test always passes
});
✓ Fixed code
test('add', () => {
  const result = add(2, 3);
  expect(result).toBe(5); // proper assertion
});

Add an assertion to verify the result. Without assertions, the test is meaningless.

How to diagnose

  • Check if the test body contains any expect() calls.

  • Verify that assertions are not inside conditionals or callbacks that might not execute.

  • Add expect.hasAssertions() at the top of the test to fail if no assertions run.

How to fix

  • Add meaningful assertions: expect(result).toBe(expectedValue).

  • Add expect.hasAssertions() or expect.assertions(n) to enforce assertion count.

  • Move assertions out of conditionals so they always execute.

  • For async tests, ensure assertions are after await or inside the resolved promise.

How to prevent

  • Add expect.hasAssertions() to tests to ensure at least one assertion runs.

  • Always verify output — a test without assertions is not a real test.

  • Use expect.assertions(n) to verify the exact number of assertions.

Related Resources

Related Glossary

Related Lessons

← Back to language