Skip to content
New issue

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

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

Already on GitHub? # to your account

[Bug]: toMatchObject on document.body makes Jest freeze #14133

Closed
elias6 opened this issue May 10, 2023 · 9 comments
Closed

[Bug]: toMatchObject on document.body makes Jest freeze #14133

elias6 opened this issue May 10, 2023 · 9 comments

Comments

@elias6
Copy link

elias6 commented May 10, 2023

Version

29.5.0

Steps to reproduce

  1. Clone the repo at https://github.com/elias6/jestFreezeTest.
  2. Run yarn.
  3. Run yarn test.
  4. Note that you see about to expect in your terminal, but not done expecting.

Expected behavior

I expect the assertion to pass and the test to finish running.

Actual behavior

Jest uses a lot of CPU, and the expect(document.body).toMatchObject(document.body); line never seems to finish.

If you try to exit Jest by pressing Ctrl+C, the process might still be running and using a lot of CPU, and not exit unless you kill it. This does not always happen though.

Additional context

I am able to reproduce this in Jest 29.2.2 (with jest-environment-jsdom@29.2.2) and Jest 29.5.0 (with jest-environment-jsdom@29.5.0). I did not try any other versions.

If you want a more realistic example of a real-world situation where this can happen, you can change the assertion to something like expect({ element: document.body }).toMatchObject({ element: document.body });, but this is not necessary.

My real-world test suite passes in Jest 29.2.2, but freezes in Jest 29.5.0, for reasons I haven't figured out.

If I remove one or more of the buttons, Jest takes a somewhat long time, then shows output like this:

yarn run v1.22.19
$ jest
  console.log
    about to expect

      at Object.log (test.js:18:11)

 FAIL  ./test.js (17.754 s)
  something
    ✕ does something (17359 ms)

  ● something › does something

    TypeError: undefined is not a function

      17 |
      18 | 		console.log("about to expect");
    > 19 | 		expect(document.body).toMatchObject(document.body);
         | 		                      ^
      20 | 		console.log("done expecting");
      21 | 	});
      22 | });

      at Object.toMatchObject (test.js:19:25)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        18.429 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Environment

System:
    OS: macOS 11.7.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 18.13.0 - /usr/local/opt/node@18/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.19.3 - /usr/local/opt/node@18/bin/npm
  npmPackages:
    jest: ^29.5.0 => 29.5.0
@Hotell
Copy link

Hotell commented May 31, 2023

we have same issues https://github.com/microsoft/fluentui/pull/28032/files#r1211527953

Besides that some matches started failing with following error
image

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jun 30, 2023
@SimenB
Copy link
Member

SimenB commented Jun 30, 2023

huh - this is a weird one... Does it happen with multiple different JSDOM versions?

@github-actions github-actions bot removed the Stale label Jun 30, 2023
@mrazauskas
Copy link
Contributor

Similar to #14375.

Could someone double check if it makes sense what I wrote in #14375 (comment)

@elchininet
Copy link

elchininet commented Jul 30, 2023

@mrazauskas,
Maybe everything is connected to globalThis as document.body has globalThis as one of its sub-properties:

document.body.ownerDocument.defaultView.globalThis === globalThis // true
document.body.ownerDocument.defaultView.globalThis === globalThis.globalThis // true

And this will happen with any DOM Node as one of the Node properties is ownerDocument.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

5 participants