RangeError: Maximum call stack size exceeded with `.toBe` on a large string
See original GitHub issue🐛 Bug Report
expect(["....big string here"]).toBe("another 3MB string");
Writing code like this, jest will throw RangeError, here is the error message:
● Test suite failed to run
RangeError: Maximum call stack size exceeded
at String.match (<anonymous>)
at exports.separateMessageFromStack.content (node_modules/jest-message-util/build/index.js:368:32)
at Array.map (<anonymous>)
the Array expect
function got has an item that is an about 3MB string (base64 image), and toBe
got the same base64 String.
To Reproduce
like above.
Expected behavior
should fail the test, but not throw range error
Link to repl or repo (highly encouraged)
envinfo
System:
OS: macOS 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Binaries:
Node: 11.2.0 - ~/.nvm/versions/node/v11.2.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v11.2.0/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:13 (5 by maintainers)
Top Results From Across the Web
javascript - Maximum call stack size exceeded error
It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you...
Read more >Uncaught RangeError: Maximum call ... - Net-Informations.Com
This error is almost always means you have a problem with recursion in JavaScript code, as there isn't any other way in JavaScript...
Read more >JavaScript RangeError: Maximum Call Stack Size Exceeded
The RangeError: Maximum call stack size exceeded is thrown when a function call is made that exceeds the call stack size. This can...
Read more >JavaScript Error: Maximum Call Stack Size Exceeded
This error is a RangeError. A RangeError typically means an error has occurred outside of a code's argument value for its parameter. Now...
Read more >Deal With “Maximum Call Stack Size Exceeded” in JavaScript
Dealing with the “Maximum call stack size exceeded” error is easy. All you have to do is avoid using the spread operator or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not entirely sure if a unit test suite does that, but think a good way of dealing with overly long lines would just be to chop to the relevant section. That would be the start of the differences + whatever surroundings can be added reasonably.
Samples for comparing against
SBjb21wcmVoZW5zaXZlIEphdmFTY3JpcHQgdGVzdGluZyBzb2x1dGlvbi4gV29ya3Mgb3V0IG9mIHRoZSBib3ggZm9yIG1vc3QgSmF2YVNjcmlwdCBwcm9qZWN0cy4K
It’s not entirely uncommon for compilers or intrepeters to chop lines to the relevant section. I’m not entirely sure how much overhead this would introduce. I’m also not sure about the UX aspects of chopping strings that should be equal but aren’t (i.E. introducing headaches to the guy debugging that test)
While it fails here https://github.com/facebook/jest/blob/736edd2ea6c9aadfb6e8794ecdc8a726f8a76b1a/packages/jest-message-util/src/index.ts#L358-L360, I think it makes more sense to avoid huge strings here: https://github.com/facebook/jest/blob/736edd2ea6c9aadfb6e8794ecdc8a726f8a76b1a/packages/jest-matcher-utils/src/index.ts#L307-L313 rather than trying to fix the regex part. This ends up generating a huge string, which is used when throwing the assertion error, which we later run the regex against. I think such a huge string is not useful anyways
That said, the change @StringEpsilon suggests seems reasonable regardless?