-
Notifications
You must be signed in to change notification settings - Fork 473
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
query* causes TypeError: Converting circular structure to JSON #875
Comments
Hi @villesau, thanks for posting this here! Thanks! |
Hi @MatanBobi, I can once I have time. One potential candidate for bug could be modal from |
@MatanBobi Ok it's actually pretty easily reproable: import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
describe('test test', () => {
it('example test', () => {
const { queryAllByText } = render(
<div>
<div>test thing</div>
<div>test thing</div>
</div>
);
expect(queryAllByText('test thing')).toEqual(123);
});
}); |
Ok, now when I tried to get minimal environment setup, I found out that updating Edit: I was actually still able to reproduce the problem :( Just not with the minimal repro I provided. I can try to provide new repro at some point. |
Actually now I can repro again even with the minimal repro. run |
I'm seeing the same thing, just setup testing library react, but so hard to figure out whats causing this |
I'm having this issue as well with something as simple as:
I tried upgrading all dependencies, querying with In the meantime, I'm getting around with snapshots. This is happening on this test file on my repo. The weird thing is that other files use it without issues. On the components, I'm using Could these functions be the culprit? I'm on node Versions for all my dependencies can be found here. |
I'm having this issue as well. This message is output to the console, and the test just keeps running nonstop. Currently at 320s as I write this. (node:54512) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON Here's the test:
The expected behavior is that the first ActionButton element should be focused on render. When I query the first ActionButton element, the test passes without issue. When I query the second ActionButton element, the issue occurs. "@testing-library/jest-dom": "5.11.4", |
Any corrections for this?
|
I couldn't reproduce locally. was this issue fixed? |
I could not find a fix for this, but I'm using findAllByRole and it doesnt throws me this error |
The error seems to happen when HTML elements are passed to Here's a crude monkeypatch to delete the circular reference when making assertions. It doesn't handle all cases and might have side-effects but it was good enough for my use case and hopefully highlights where the issue lies. In global setup file ("setupFilesAfterEnv"):
I would argue this is a bug in Jest rather than a bug in testing-library. Jest should be able to format objects with circular references or at least give an informative error message. |
I had the circular error issue with this code
For now, resorted to the following workaround:
|
is this fixed? having the same problem |
@inust33 we're waiting for a reproducible example because at the moment I wasn't able to reproduce this in order to work on a fix. |
Was able to reproduce generating an app with create-react-app and then adding this test to App.test.js:
Versions in package.json:
|
@agmcleod could you reproduce it in a GitHub repo or a codesandbox? https://codesandbox.io/s/kind-noether-rnt4gl?file=/src/index.test.js |
@timdeschryver pushed up here: https://github.com/agmcleod/testinglib-cyclic-error, sadly though it seems to be intermittent for me. I can re-run it multiple times in a row and it will be fine. But occasionally I will see:
|
Thanks @agmcleod for taking the time to create this one, it's extremely helpful! Just to be sure, when you're saying "will be fine" you mean that the test will fail? because it won't pass since there is an element with that text in the DOM. |
Correct. The test will fail, but with an expected outcome of that it finds the element instead of an empty array. |
Thanks for this. |
Digging into it, this looks heavily related to this issue in jest. |
I'm closing this one as this is a jest issue and will do my best to assist in fixing the jest issue as I understand that this might happen in every react app on a failing test. |
I also got this error by leaving a console.log in the test! whoops! |
EDIT: Updated to reflect my latest findings
@testing-library/dom
version: 7.29.4Relevant code or config:
What you did:
I was trying to query deep element for clicking it. The page contains two matching components with the same text
What happened:
I'm getting following:
Reproduction:
jest --watch
(babel and jest configs can be very basic or even default)The error happens when Jest runs the snippet for second time or more. It can be resolved by wiping the query cache using
jest --clearCache
, but it reappears on second test run.Problem description:
The test crashes and leaves Jest hanging. This does not happen if I'm not querying the component with anything, but does happen when querying, at least with
queryByText
andqueryAllByText
.Suggested solution:
The above example should not crash. I hope the stacktrace and the description gives enough clue on what might be the culprit here.
The text was updated successfully, but these errors were encountered: