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

test.only should be scoped to its describe #9014

Closed
dandv opened this issue Oct 6, 2019 · 9 comments
Closed

test.only should be scoped to its describe #9014

dandv opened this issue Oct 6, 2019 · 9 comments

Comments

@dandv
Copy link
Contributor

dandv commented Oct 6, 2019

🐛 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

@thymikee
Copy link
Collaborator

thymikee commented 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.

@dandv
Copy link
Contributor Author

dandv commented Oct 6, 2019

@thymikee If I'm reading @SimenB's example correctly, the "all non-auth tests" are intended to execute whether the USER and PASSWORD are set or not. However, that's not the case.

@thymikee
Copy link
Collaborator

thymikee commented Oct 6, 2019

I'm pretty sure he meant separate files instead of multiple describes. It's just an example code, don't expect it to be valid.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@dandv
Copy link
Contributor Author

dandv commented Mar 1, 2022

Agree that a describe.only should focus the testing on that single describe.

A test.only within a describe.only would focus on that test.

A test.only within a describe is ambiguous. I assumed, per POLA that it would be scoped to the describe, as other tests are.

@github-actions github-actions bot removed the Stale label Mar 1, 2022
@SimenB
Copy link
Member

SimenB commented 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)

@github-actions
Copy link

github-actions bot commented Mar 2, 2023

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 2, 2023
@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2023
@github-actions
Copy link

github-actions bot commented May 2, 2023

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 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants