Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeouts to test.each implementations #6749

Closed
carusology opened this issue Jul 24, 2018 · 2 comments 路 Fixed by #6660
Closed

Add timeouts to test.each implementations #6749

carusology opened this issue Jul 24, 2018 · 2 comments 路 Fixed by #6660

Comments

@carusology
Copy link

馃殌 Feature Proposal

As of right now, you can set the timeout for an individual test() invocation by setting the timeout parameter to the number of milliseconds you want a test to run. It is well documented here. However, that functionality is lacking for test.each(). I propose that test.each() is updated such that if you pass a timeout to its third argument, it sets a timeout for each iteration of the test as it does for the individual test().

Motivation

The consumer of Jest will have a more consistent API for test() and test.each() implementations, where the latter is merely a parameterized version of the former.

Example

I have an integration test that converts pdfs into images at various "chunk sizes", ensuring that only a specific number of pages are being converted at a time in order to prevent the conversion process from consuming too many resources. However, the end result should always be the same regardless of "chunk size." This particular test requires converting images and regularly takes more than 5 seconds. It should take less time than my failure cases which should return almost instantly.

test.each([ 1, 2, 3, 4, 5 ])
  ('resolves for chunk sizes of "%p"', async (chunkSize) => {

    // Arrange

    let converter = new ImageConverter(...);
    let expected = [ { ... pageOne ... }, { ... pageTwo ... } ];

    // Act

    let actual = converter.convert(options);

    // Assert

    expect.assertions(1);
    await expect(actual).resolves.toEqual(expected);
  }, 10000 /* The timeout is now 10s instead of 5s for each iteration of test.each */
);

Pitch

(Why does this feature belong in the Jest core platform?)

It already exists within the Jest core platform! :) I actually expected it to be there when I worked with the framework. Today, since there is no error if you set the timeout on a test.each implementation, Jest fails with a timeout of 5s as it does by default, and you have to look at the documentation to see that it actually isn't supported for parameterized tests as it is for individual ones. I think this is a clear cut situation where expectations and reality clash.

@SimenB
Copy link
Member

SimenB commented Jul 25, 2018

We have an open PR for this 馃檪 #6660

thymikee pushed a commit that referenced this issue Aug 9, 2018
## Summary

Add test/describe timeout support

 - Fixes feature parity to [testname-fn-timeout](https://jestjs.io/docs/en/api#testname-fn-timeout) etc

Fixes #6749
## Test plan

 - Updated `jest-each` unit tests
 - Remove duplicate unit tests in `jest-jasmine2` (we have integration tests that cover this so no need to maintain the unit tests in two places)
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants