Skip to content

Invalid assertion: matcher does not exist

Quick summary

Your test uses a matcher like toBeGreaterThan or toMatchSnapshot that the test framework does not recognize.

Why this happens

  • The matcher name is misspelled or does not exist in the test framework

  • The matcher is from a plugin or extension that is not installed or imported

  • The test framework version does not support the matcher being used

Minimal example

✗ Broken code
test('checks value', () => {
  expect(5).toBeGreaterThen(3); // typo: Then instead of Than
});
✓ Fixed code
test('checks value', () => {
  expect(5).toBeGreaterThan(3); // correct matcher name
});

Correcting the matcher name to toBeGreaterThan matches the test framework's API and the assertion works.

How to diagnose

  • Check the test framework documentation for the correct matcher name and syntax

  • Verify that any required plugins or extensions for the matcher are installed

  • Check the test framework version and compare with the matcher's availability

How to fix

  • Correct the matcher name to match the test framework's API

  • Install and import the plugin that provides the custom matcher

  • Upgrade the test framework to a version that supports the matcher

How to prevent

  • Use TypeScript types for the test framework to catch invalid matchers at compile time

  • Keep test framework and plugins updated and refer to current documentation

Related Resources

Related Glossary

Related Lessons

← Back to language