I use Create React App and already declare this on src/setupTests.js:
import '@testing-library/jest-dom';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
But every time I use expect(anything).toBeInTheDocument()
on test file, when running the test I get:
TypeError: expect(...).toBeInTheDocument is not a function
To make sure that the setupTests.js is actually run, I try to use enzyme shallow on test file and it works. So what is the problem with jest-dom actually and how to solve it?
Solved with:
import '@testing-library/jest-dom/extend-expect';
on src/setupTests.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With