-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
iterables and toHaveBeenCalledWith result in RangeError: Maximum call stack size exceeded #6830
Comments
Note that |
Minimum reproduction in Jest's own test suite: diff --git i/packages/expect/src/__tests__/utils.test.js w/packages/expect/src/__tests__/utils.test.js
index 6a5e7d909..8ba302d89 100644
--- i/packages/expect/src/__tests__/utils.test.js
+++ w/packages/expect/src/__tests__/utils.test.js
@@ -13,6 +13,7 @@ const {
emptyObject,
getObjectSubset,
getPath,
+ iterableEquality,
subsetEquality,
} = require('../utils');
@@ -150,3 +151,17 @@ describe('subsetEquality()', () => {
expect(subsetEquality(undefined, {foo: 'bar'})).not.toBeTruthy();
});
});
+
+describe('iterableEquality()', () => {
+ test('self-returning iterator does not explode', () => {
+ class Iter {
+ *[Symbol.iterator]() {
+ yield this;
+ }
+ }
+
+ const val = new Iter();
+
+ expect(iterableEquality(val, val)).toBe(true);
+ });
+}); From what I can understand it recurses forever here: https://github.com/facebook/jest/blob/c9893d2f1cdbc98655ca446d2a49f8c77a42b4be/packages/expect/src/utils.js#L183-L188 Not sure how to handle it. Bail after say 1000 iterations? If |
@thymikee @rickhanlonii thoughts? |
I'm no expert about this, but would checking reference equality helps? |
Yeah, I think so. But for how many iterations should we do that before bailing? Maybe somebody has an iterator delivering fibonacci numbers - there are cases for infinite generators. Not sure what would give the best DX here |
I think bailing after 1000 makes sense, we can up it if necessary |
Hi, I am a student of computer and software engineering and I choose this issue to work on in my software engineering subject so I'm no expert on this. As I was trying to understand this issue I looked into the comments and saw that the problem may be fixed if the cycle referenced above is changed. Would you give me some tips and help? Thanks a lot! |
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. |
🐛 Bug Report
If
toHaveBeenCalledWith
is used with an iterable,RangeError: Maximum call stack size exceeded
will be thrown.To Reproduce
Steps to reproduce the behavior:
Run
This results in:
Expected behavior
The test passes.
Link to repl or repo (highly encouraged)
Code given above
Run
npx envinfo --preset jest
Paste the results here:
It results in an error for me. I don't think it's what you want, but I will paste it here anyway.
Here's the version in
package.json
The text was updated successfully, but these errors were encountered: