react-testing-library: [4.1.3] Cannot find module 'jest-dom/extend-expect'

  • react-testing-library version: 4.1.4
  • react version: 16.4.1
  • node version: 9.11.1
  • npm (or yarn) version: yarn 1.3.2

Relevant code or config:

// occurring error this line
import 'jest-dom/extend-expect'

entire test code https://github.com/ryota-murakami/redux-boilerplate-less-architecture/blob/master/src/pages/github/index.test.js

What you did:

What happened:

Test Broke with Cannot find module 'jest-dom/extend-expect'

Reproduction:

I don’t know why is that happening because there is no jest-dom change [https://github.com/kentcdodds/react-testing-library/compare/v4.1.2...v4.1.3](between v4.1.2 v4.1.3).

something of dom-testing-liblary? thanks😀

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

If some of you still have the problem: I fixed it by using

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

instead of jest-dom/jest-dom/extend-expect

This is the recommanded usage by the official documentation

yarn add -D @testing-library/jest-dom

replace import “jest-dom/jest-dom/extend-expect”; with import “@testing-library/jest-dom/extend-expect”;

It’s a separate package

npm install -D jest-dom
# or yarn
yarn add --dev jest-dom

If some of you still have the problem: I fixed it by using

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

instead of jest-dom/jest-dom/extend-expect

This is the recommanded usage by the official documentation

Thanks it works for me.

You have to install jest-dom manually. Good luck!

Step 1: Uninstall jest-dom(deprecated one) npm uninstall jest-dom

Step 2:Install testing-library/jest-dom npm i @testing-library/jest-dom

Step 3:Replace import “jest-dom/jest-dom/extend-expect”; with import “@testing-library/jest-dom/extend-expect”;

Thanks @stevenYouhana

any update on this? There’s still a lot of mixed info out there - jest-dom is now packaged in, toBeInTheDocument must come from jest-dom, jest-dom is deprecated, it’s @testing-library/jest-dom now, you need to import it, you don’t need to import it… All the set-up guides are out of date.

If I import {toBeInTheDocument} from '@testing-library/jest-dom' then I’m told Cannot find module '@testing-library/jest-dom' and if I don’t then TypeError: expect(...).toBeInTheDocument is not a function

https://github.com/testing-library/jest-dom#installation

FYI Currently the official documentation recommend us to use

// In tsconfig.json "include": [ "./jest-setup.ts"],

I’ve done that; its in my package.json (^3.1.3)

I am still getting this error nothing is fixing it OK I just got this error

jest-dom has moved to @testing-library/jest-dom. Please uninstall jest-dom and install @testing-library/jest-dom instead, or use an older version of jest-dom. Learn more about this change here: https://github.com/testing-library/dom-testing-library/issues/260 Thanks!

@s-Hale Did you install @testing-library/jest-dom? Either via https://github.com/testing-library/jest-dom#installation or yarn add -D @testing-library/jest-dom

I am having the same problem - what does “You have to install jest-dom manually.” mean? Thanks.