Non-termination of test execution in Jest when tested function mutates its arguments
See original GitHub issueš Bug Report
In some situations test execution doesnāt appear to terminate. It also does not run into a timeout. I suspect this can happen when the tested function mutates its arguments. I have only observed this with Jest, so Iām not sure if this is rather a Jest issue.
To Reproduce
Consider the following example (full setup available in this repository):
const fc = require('fast-check')
// the function to be tested
function nasty(array) {
array.push(1) // nasty argument mutation
return array
}
test('demo test', () => {
fc.assert(fc.property(
fc.array(fc.integer()),
array_before => {
const array_after = nasty(array_before)
// some random assertion that should eventually fail
expect(array_after.length).toBeLessThenOrEqual(3)
}
))
})
If I run this with Jest, it looks like this. Note, if I pass a copy of array_before
into nasty
, the test run terminates immediately (with a failure as expected). So I really think the argument mutation is the offender here.
Your environment
Packages / Softwares | Version(s) |
---|---|
fast-check | 3.1.4 |
node | v16.0.5 |
jest | 29.0.3 |
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Testing Asynchronous Code - Jest
Promisesā. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test...
Read more >Jest did not exit one second after the test run has completed.
Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped...
Read more >Jest : Your First Test
Tests run when changes are made to the code in your projects. ... The test function takes two arguments: test(arg1, arg2) .
Read more >Jest Testing Tutorial: 5 Easy Steps - Testim Blog
To solve this problem, we can use the beforeEach and afterEach functions to avoid code duplication. Both functions allow you to execute logicĀ ......
Read more >Unit Testing with Jest | CS4530, Spring 2022
Unit testing is not a new concept; it has been around for a long time. āUnit tests are often automated tests prepared and...
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
Good news: I have some ideas to make it work with, I hope, no runtime footprint but probably a huge memory footprint as Iāll have to keep one copy of the array in memory to make the code work. Iāll work on it soon and assess impacts to check whether acceptable or not. The risk of side effects being huge, it does not seem that an issue to try to limit that kind of issues to the end user a little bit more if feasible without any excessive impact.
Letās keep it opened for now so that I can have a reminder that there is possibly a quick improvement to do for the shrinker of arrays.