Repository navigation
What is the use case of sub tests #51359
Copy link
Copy link
Closed
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.questionIssues asking questions about Node.js.Issues asking questions about Node.js.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Description
Activity
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Jan 4, 2024 AFAIK it's the same behavior as BDD syntax (describe, it) @nodejs/test_runner
Reacted by Moshe Atlow and Scotty Jamison- addedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on Jan 4, 2024 its just another flavor/syntax for authoring tests. the behavior is pretty much the same
Improvements to the documentation are always welcomed
@theScottyJam i'm not aware of a test runner that doesn't support subtests - do you have one in mind that doesn't?
- added a commit that references this issue
on Jan 7, 2024 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.
- added a commit that references this issue
on Jan 12, 2024 - added a commit that references this issue
on Jan 19, 2024 - added a commit that references this issue
on Feb 15, 2024
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.questionIssues asking questions about Node.js.Issues asking questions about Node.js.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Affected url(/sitelet?url=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2Fs)
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?