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

What is the use case of sub tests #51359

Closed
theScottyJam opened this issue Jan 4, 2024 · 5 comments · Fixed by #51379
Closed

What is the use case of sub tests #51359

theScottyJam opened this issue Jan 4, 2024 · 5 comments · Fixed by #51379
Labels
doc Issues and PRs related to the documentations. question Issues that look for answers. test_runner Issues and PRs related to the test runner subsystem.

Comments

@theScottyJam
Copy link

theScottyJam commented Jan 4, 2024

Affected URL(s)

https://nodejs.org/api/test.html#subtests

Description of the problem

Node describes this concept of a subtest, which was a novel concept to me - I'm not aware of any other test runner that does this sort of thing (not that I'm deeply familiar with tons of different test runners though). It's difficult to piece together from the small bit of documentation what subtests are meant for. My first impression was that they were just another way of doing the typical describe/it pattern - the parent test being the "describe" block and the subtests being the "it"s. But Node also provides explicit support for describe, so as far as I can tell that's not supposed to be it.

More recently, I figured out a different powerful use for it. You can do "arrange" and "act" logic in the parent test, and then different "assert"s in a number of subtests, thus allowing those asserts to fail independent of each other. This seemed really powerful to me, but then I found out that using sub-tests in this way created problems - specifically, if you were also using a beforeEach() or afterEach(), those would get run between every subtest, potentially cleaning things up between them, which could be problematic if your future subtests still needed things to not be cleaned up. I would assume that if what I was describing was really the intended use for them, then beforeEach() and afterEach() would be designed differently so as to not run on every subtest, only the parent test.

So, what is the use of these subtests? And could we update the documentation to help people like me who aren't familiar with this concept? Maybe by providing a more realistic example or something?

@theScottyJam theScottyJam added the doc Issues and PRs related to the documentations. label Jan 4, 2024
@marco-ippolito
Copy link
Member

AFAIK it's the same behavior as BDD syntax (describe, it) @nodejs/test_runner

@marco-ippolito marco-ippolito added question Issues that look for answers. test_runner Issues and PRs related to the test runner subsystem. labels Jan 4, 2024
@MoLow
Copy link
Member

MoLow commented Jan 4, 2024

its just another flavor/syntax for authoring tests. the behavior is pretty much the same

@MoLow
Copy link
Member

MoLow commented Jan 4, 2024

Improvements to the documentation are always welcomed

@ljharb
Copy link
Member

ljharb commented Jan 6, 2024

@theScottyJam i'm not aware of a test runner that doesn't support subtests - do you have one in mind that doesn't?

nodejs-github-bot pushed a commit that referenced this issue Jan 7, 2024
PR-URL: #51379
Fixes: #51359
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
@theScottyJam
Copy link
Author

Sorry for the delay in responding, and thanks for addressing the concerns - the documentation changes look great.

To @ljharb's point, the test runners I've used in the past are Mocha, Jasmine, and Jest, and as far as I can tell, none of those support subtests (though I haven't thoroughly read through all of the documentation of each one). I did find this issue confirming that Mocha doesn't support it.

marco-ippolito added a commit to marco-ippolito/node that referenced this issue Jan 12, 2024
PR-URL: nodejs#51379
Fixes: nodejs#51359
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Medhansh404 pushed a commit to Medhansh404/node that referenced this issue Jan 19, 2024
PR-URL: nodejs#51379
Fixes: nodejs#51359
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
targos pushed a commit that referenced this issue Feb 15, 2024
PR-URL: #51379
Fixes: #51359
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
richardlau pushed a commit that referenced this issue Mar 25, 2024
PR-URL: #51379
Fixes: #51359
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
richardlau pushed a commit that referenced this issue Mar 25, 2024
PR-URL: #51379
Fixes: #51359
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. question Issues that look for answers. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants