question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

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.

https://user-images.githubusercontent.com/26570572/192302053-fb7586fb-a8e1-4c1a-b44a-d5b9d41a90c1.mov

Your environment

Packages / Softwares Version(s)
fast-check 3.1.4
node v16.0.5
jest 29.0.3

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dubzzzcommented, Oct 5, 2022

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.

1reaction
dubzzzcommented, Sep 29, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found