kentcdodds / jest-cypress-react-babel-webpack

Configure Jest for Testing JavaScript Applications and Install, Configure, and Script Cypress for JavaScript Web Applications on TestingJavaScript.com
https://testingjavascript.com
Other
512 stars 329 forks source link

react-testing-library is deprecated so installed @testing-library/react but now test fails #20

Closed interglobalmedia closed 5 years ago

interglobalmedia commented 5 years ago

I got the following in Terminal:

Cannot find module 'react-testing-library/cleanup-after-each' from 'auto-scaling-text.test.js'

    > 1 | import 'react-testing-library/cleanup-after-each'
        | ^
      2 | import React from 'react'
      3 | import { render } from 'react-testing-library'
      4 | import AutoScalingText from '../auto-scaling-text'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (src/shared/__tests__/auto-scaling-text.test.js:1:1)

 PASS  src/shared/__tests__/utils.test.js

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.699s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

How can we import cleanup-after-each now? Or is it even available?? Thanks.

DanceParty commented 5 years ago

I believe you can accomplish the same thing by following the docs here:

https://testing-library.com/docs/react-testing-library/setup#cleanup

interglobalmedia commented 5 years ago

Thanks @DanceParty. I already made the change by simply "guessing". Is there new documentation for the "new" library" relating to other things? Or is everything the same except for the name of the library? Thanks!

DanceParty commented 5 years ago

So if you wanted to stick as close to the tutorial as possible, I believe you can also just:

import '@testing-library/react/cleanup-after-each'

in the begining of the test file as well :)"

The new docs are listed here: https://testing-library.com/docs/react-testing-library/intro

interglobalmedia commented 5 years ago

Thanks. That's what I did. And thanks for the list to the new docs. I use the library in a number of my apps, but with the old version so the link will be very helpful. Thanks!