0

We have been using Enzyme for a long time to test our react components but have started the migration to React Testing Library step by step.

When trying to use the toHaveValue matcher in a RTL test it failes since the enzyme matcher with the same name is called instead. Is there a way I can "tell" a specific test file to use the matchers from jest-dom instead?

I have added both the enzyme and jest-dom matchers to my repository according to the installation docs.

Ola
  • 150
  • 1
  • 6

1 Answers1

0

The toHaveValue() assertion is provided by react-testing-library's jest-dom (https://github.com/testing-library/jest-dom#tohavevalue).

You should be able to force the jest-dom matchers (assertions) "before" whichever ones you have loaded previously (enzyme's, for example) by putting

import "@testing-library/jest-dom/extend-expect";

at the top of your test.

See also: https://github.com/testing-library/react-testing-library/issues/379 and https://github.com/facebook/jest/issues/6243

A similar issue: https://github.com/testing-library/jest-dom/issues/208

snicker
  • 11
  • 2