test.only should be scoped to its describe
See original GitHub issue🐛 Bug Report
In a describe
, I have a bunch of tests that should be executed only when a certain condition is fulfilled. One official solution is to use test.only
.
The problem is that if the condition is truthy, no other test in the entire test file, that is, in different describe
s, gets executed. Instead, I see Pending test 'xxx'
for every single test in all describes.
To Reproduce
describe('always run', () => {
test('add', () => {
expect(1 + 2).toBe(3);
});
});
describe('run conditionally', () => {
if (true) test.only('skipping all other things', () => {
console.warn('skipping tests');
});
test('mul', () => {
expect(2 * 3).toBe(6);
})
});
Expected behavior
Only the tests in the describe
block containing the test.only
call should be skipped. Otherwise, test.only is a kill switch for the entire test file.
Link to repl or repo (highly encouraged)`
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Test Scope | Test IO Academy
The scope of a test defines what areas of a customer's product are supposed to get tested, what functionalities to focus on, what...
Read more >What is in your Testing Scope? - Medium
The testing scope is a high-level list of product parts that have to be tested in order to gain a reliable assessment of...
Read more >Tips to Define Test Scope for Software Testing - KiwiQA
Listed below are some basic guidelines that show how you can properly define your test scope for software product testing.
Read more >How to limit the scope of Jest mocked functions to a single test
I understand what is happening: myApi is imported into the shared scope of both tests. And this is why the .mockResolvedValue* applies "across" ......
Read more >Test Cycle - Define Test Scope and Test Assignment
Test cycle is a space from where the test executions actually happen. Multiple test cycles can be created in a test plan due...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is certainly not a bug, but rather a feature request. We can discuss if it makes sense to scope
test.only
to a describe. IMHO we shouldn’t, because it exists to focus on a single test case. Or a whole describe withdescribe.only
.I don’t think we should do this.
only
means “only this” (or “these” if added to multiple tests) within a test suite (file), not just within itsdescribe
. This is, afaik, also the case in other test runners with the samedescribe
API (at least mocha)