Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not play well with jest 27 #918

Closed
TrejGun opened this issue May 26, 2021 · 15 comments · Fixed by #931
Closed

does not play well with jest 27 #918

TrejGun opened this issue May 26, 2021 · 15 comments · Fixed by #931
Assignees
Labels
bug Something isn't working

Comments

@TrejGun
Copy link

TrejGun commented May 26, 2021

  • @testing-library/react version:

"@testing-library/jest-dom": "5.12.0",
"@testing-library/react": "11.2.7",

  • Testing Framework and version:

"jest": "27.0.1",

  • DOM Environment:

jsdom

Relevant code or config:

please refer to this project
https://github.com/TrejGun/casino

What you did:

updated jest from 26 to 27

What happened:

Tests are now failing with

    ReferenceError: clearImmediate is not defined

Reproduction:

see above

Problem description:

Tests are failing :(

Suggested solution:

N/A

@ediblecode
Copy link

@TrejGun it looks like this was a breaking change in Jest 27, see https://github.com/facebook/jest/blob/master/CHANGELOG.md#fixes-2. Specifically:

[jest-environment-jsdom] [BREAKING] Remove Node globals setImmediate and clearImmediate #11222

See also testing-library/dom-testing-library#914 which looks related.

@eps1lon eps1lon added the bug Something isn't working label May 26, 2021
@eps1lon eps1lon self-assigned this May 26, 2021
@andrevenancio
Copy link

andrevenancio commented May 27, 2021

With RTL:

"@testing-library/dom": "^7.30.0",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^13.0.10",

And Jest version 27.0.1

I'm getting TypeError: Cannot destructure property 'AsymmetricMatcher' of '_prettyFormat.default.plugins' as it is undefined.

@tdeekens
Copy link

Seeing the same problems. Will be even be possible for rtl to work in v26 and v27 of Jest with the same version?

@dodoongtak
Copy link

dodoongtak commented Jun 2, 2021

[Date: 2 June 2021]

with RTL:

//dev dep
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"jest": "^27.0.3",

//dep
"react": "^17.0.2",

After updating jest version: 26 -> 27

Following Error Message Prompts out.

The error below may be caused by using the wrong test environment. See https://jestjs.io/docs/configuration#testenvironment-string.

Consider using the "jsdom" test environment.

ReferenceError: document is not defined


As I've looked over the PRs mentioned this issue,

@kentcdodds has already recognized the issue regarding the jest27 updates on switching default test env from jsdom to node.
Discussion here: kentcdodds/kcd-scripts#210

Applause for @eps1lon 👏👏👏


Unfortunately, I could not clearly figure out the future action plan to resolve this breaking change of jest.

  1. Would it be switching to node as default test env in testing-library?

Or

  1. As mentioned in the jest blog post regarding 27update, we still can configure testEnvironment as jsdom instead of node.

Would it be still using jsdom though they suggest node?

FYI:
The flipping default - Breaking Change started from jestjs/jest#9874

@m4thieulavoie
Copy link

Having the same issue after upgrading to Jest@27. Is anyone working on a fix?

@eps1lon
Copy link
Member

eps1lon commented Jun 3, 2021

Having the same issue after upgrading to Jest@27. Is anyone working on a fix?

We're in the process of fixing this in @testing-library/dom. This particular issue should already be fixed in the alpha but it'll take some time to test it before we can release a new major of @testing-library/react.

@jRichardeau
Copy link

Hello,

Facing same issue but it seems to work for @testing-library/dom < 7.29.6, so when forcing the 7.29.5 version in the dependencies of my package.json it solved my problem.

@marybeshaw
Copy link

marybeshaw commented Jun 11, 2021

We have the same issue. Trying to update a monorepo with 297 test suites to jest v27 caused a full 47 test suites to fail. A couple of issues I saw:

  • Something is wrong with promise cleanup. A test of code that relied on .finally() timed out and never finished.
  • Something is wrong with timers, both real and fake. It's possible this is just another symptom of the promise cleanup issue.
  • Clearing a mocked Date.now (created using jest.spyOn) failed (Date.now.mockClear() threw an error that mockClear wasn't a function).
  • New messages:ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down.. These are probably leaks I could fix if I could figure out which test was being torn down.

Jest 27 config file changes I made:

  testEnvironment: 'jsdom',
  timers: 'legacy',
  testRunner: 'jasmine2',

@tdeekens
Copy link

Same issues here but also not only rtl related.

  1. Promises: native Promises (not polyfilled) do not seem to be controlable by Jest v27 making tests fail
  2. Timers: the internal change to use sinon (in v27) seems to have the impact of jest not being able to control time when using core-js (it does overwrite some thing)

It turned out that disabling core-js under test for us was generally a good idea. However, leaving us with the issue that jest v27 seems to struggle with native promises.

@eps1lon eps1lon linked a pull request Jun 12, 2021 that will close this issue
3 tasks
@eps1lon
Copy link
Member

eps1lon commented Jun 13, 2021

Closed in #931

@eps1lon eps1lon closed this as completed Jun 13, 2021
@eps1lon
Copy link
Member

eps1lon commented Jun 13, 2021

🎉 This issue is fixed in version 12.0.0-alpha.2 🎉

The release is available on:

@Nmaxime
Copy link

Nmaxime commented Jul 12, 2021

I got this error :
TypeError: Cannot destructure property 'AsymmetricMatcher' of '_prettyFormat.default.plugins' as it is undefined

My packages installed :

@testing-library/react@12.0.0
@testing-library/dom@8.1.0
jest@27.0.6
ts-jest@27.0.3

@MatanBobi
Copy link
Member

I got this error :
TypeError: Cannot destructure property 'AsymmetricMatcher' of '_prettyFormat.default.plugins' as it is undefined

My packages installed :

@testing-library/react@12.0.0
@testing-library/dom@8.1.0
jest@27.0.6
ts-jest@27.0.3

@maximeNaulleau Can you please share which version of pretty-format you have installed? It should be 27^.

@signal-intrusion
Copy link

signal-intrusion commented Aug 3, 2021

@MatanBobi I get the same error. I installed pretty-formatter@27.0.6.

some-package@2.0.0 /Users/some-package
├── @babel/cli@7.14.5
├── @babel/core@7.14.6
├── @babel/preset-env@7.14.7
├── @babel/preset-react@7.14.5
├── @testing-library/react@12.0.0
├── @testing-library/user-event@13.2.0
├── @types/debug@4.1.6
├── @types/enzyme@3.10.9
├── @types/jest@26.0.24
├── @types/lodash@4.14.171
├── @types/react-datepicker@3.1.8
├── @types/react-dom@17.0.9
├── @wojtekmaj/enzyme-adapter-react-17@0.6.3
├── camelize@1.0.0
├── core-js@3.15.2
├── debug@4.3.2
├── enzyme@3.11.0
├── enzyme-adapter-react-16@1.15.6
├── jest@27.0.6
├── keyboardjs@2.6.4
├── lodash@4.17.21
├── nanoid@3.1.23
├── pretty-format@27.0.6
├── prop-types@15.7.2
├── UNMET PEER DEPENDENCY react@17.0.2
├── react-datepicker@3.8.0
├── UNMET PEER DEPENDENCY react-dom@17.0.2
├── react-input-autosize@3.0.0
├── react-intl@5.20.4
├── react-test-renderer@17.0.2
├── recompose@0.30.0
└── typescript@4.3.5

@MatanBobi
Copy link
Member

MatanBobi commented Sep 12, 2021

@MatanBobi I get the same error. I installed pretty-formatter@27.0.6.

You don't need to install it on your own, it should be a dependency for testing-library/dom.
Can you run npm ls pretty-format and share the result please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.