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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeAll and afterAll get executed if test.todo is present in describe.skip. #11006

Open
jarod-legault opened this issue Jan 15, 2021 · 6 comments

Comments

@jarod-legault
Copy link

jarod-legault commented Jan 15, 2021

馃悰 Bug Report

If there is a describe block with a beforeAll and/or afterAll and a test.todo, the beforeAll and/or afterAll will get executed even if the describe is changed to describe.skip.

To Reproduce

  • Create a new project with yarn init.
  • Install jest with yarn add -D jest.
  • Create a beforeAll.test.js file in the root of the project.
  • Add this code in beforeAll.test.js:
describe.skip( "describe block", () => {

  beforeAll( async () => {
    console.log( "beforeAll()" );
  } );

  afterAll( async () => {
    console.log( "afterAll()" );
  } );

  beforeEach( async () => {
    console.log( "beforeEach()" );
  } );

  afterEach( async () => {
    console.log( "afterEach()" );
  } );

  test( "logs a message to the console", async () => {
    console.log( "It logs a message to the console." )
  } );

  test.todo( "Future test" );

} );
  • Run the test with npx jest beforeAll.test.js. You will see the console.log statements for the beforeAll and afterAll, but not for the beforeEach and afterEach.
  • Comment out the test.todo line and run npx jest beforeAll.test.js. You will not see any console.log statements.

Expected behavior

Having a test.todo should not cause the beforeAll and afterAll to run in a skipped describe block.

Link to repl or repo (highly encouraged)

repl.it reproduction

envinfo

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
  Binaries:
    Node: 15.2.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.0.10 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3 
@joshuapinter
Copy link

+1 todos should be skipped in describe.skip blocks. Otherwise, we are commenting out these todo specs and we're losing the value of using the todo in the first place as a placeholder for specs to be written.

@gomain
Copy link

gomain commented Oct 11, 2022

I have observed that beforeAll and afterAll are also executed even when all tests in the describe block would be skipped for other reasons, such as a .only in another nested describe.

describe("outter", () => {
  describe("inner1", () => {
    beforeAll(async () => {
      console.log("should not execute, but does");
    });
    it("is skipped", async () => {
      console.log("is not executed, as expected");
    });
  });
  describe("inner2", () => {
    it.only("the only test", async () => {
      console.log("is executed, as expected");
    });
  });
});

Is it correct to expect some suit analysis such that before/afterAll are only executed if, and only if, there are tests to be run. Currently they act as special test cases where there is control over order of execution, one being first, the other being last. But not partake in the .only or .skip mechanism. And have no relation to what they are to be run before or after.

@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 30 days.

@SimenB
Copy link
Member

SimenB commented Oct 11, 2023

Happy to take a PR 馃憤

@nolleto
Copy link

nolleto commented Dec 21, 2023

Hey @jarod-legault, it this still an issue?

Because, I tried to run locally the same test scenario you shared and the beforeAll() and afterAll() logs didn't show up.

@falkenhawk
Copy link

Hasn't it been fixed in #10806 already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants