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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mistakenly nested tests neither run nor result in an error #5178

Closed
TrueWill opened this issue Dec 25, 2017 · 7 comments
Closed

Mistakenly nested tests neither run nor result in an error #5178

TrueWill opened this issue Dec 25, 2017 · 7 comments

Comments

@TrueWill
Copy link

Example:
https://repl.it/repls/CavernousElegantIvorybilledwoodpecker

When test cases get long, it's possible to mistakenly write a test case inside of another test case. Sometimes humans get mixed up on parentheses and braces.

When this happens, the internal test() method does not execute, and no errors are shown. Thus it's easy to add a test case that never runs.

I can't think of a reason to nest test cases, so my feeling is the expected behavior would be to raise an error in this situation.

@cpojer
Copy link
Member

cpojer commented Dec 25, 2017

Can you try this with Jest 22? We changed this to throw! Happy to reopen if it’s not fixed.

@cpojer cpojer closed this as completed Dec 25, 2017
@SimenB
Copy link
Member

SimenB commented Dec 25, 2017

In #4039, for reference.

We should probably have a test for that behavior...

@TrueWill
Copy link
Author

@cpojer It works exactly as I would like under Jest 22! Excellent error messages! Thank you!

Tests cannot be nested. Test adds 2 + 3 to equal 6 cannot run because it is nested within adds 1 + 2 to equal 3.

@mohanraj-r
Copy link

I came across this issue when trying to write nested data driven tests .. e.g. for each browser.. for each site .. but got error "Tests cannot be nested."
Is disallowing nested tests by design? Can you explain why please. @SimenB

@thymikee
Copy link
Collaborator

Use describe for nesting and test.each for multiple cases

@mohanraj-r
Copy link

Thanks a lot @thymikee
Didn't know about describe.each()

@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

No branches or pull requests

5 participants