question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 describes, 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)`

https://repl.it/repls/SillyPastDictionary

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
thymikeecommented, Oct 6, 2019

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 with describe.only.

0reactions
SimenBcommented, Mar 2, 2022

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 its describe. This is, afaik, also the case in other test runners with the same describe API (at least mocha)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found