Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got TypeError: expect(...).toBeInTheDocument is not a function even after proper setup

Tags:

jest-dom

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?

like image 466
Inovramadani Avatar asked Jul 17 '20 09:07

Inovramadani


1 Answers

Solved with:

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

on src/setupTests.js

like image 190
Inovramadani Avatar answered Sep 28 '22 18:09

Inovramadani