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

Assertions in test modules outside test functions are included in the count validated by expect.assertions() in the first test #8906

Closed
h4l opened this issue Sep 3, 2019 · 4 comments

Comments

@h4l
Copy link

h4l commented Sep 3, 2019

馃悰 Bug Report

Assertions in test modules outside test functions are included in the count validated by expect.assertions() of the first test. This seems to be the same issue as described in the previously closed #5887.

To Reproduce

Clone this example/reproduction repo, npm install and run the tests; they'll fail but should pass: https://github.com/h4l/jest-expect-assertions-bug

Example from that repo:

beforeAll(() => {
    expect(0).toBe(0);
});

// Uncommenting this stops the first test failing
// test('dummy', () => undefined);

// The first test here fails (with 2 assertions instead of 1),
// second and third pass.
test.each([[1], [2], [3]])( 'example test %# ', x => {
    expect.assertions(1);
    expect(x).toBeGreaterThan(0);
});

Expected behavior

The assertion count validated by expect.assertions() in test functions should be independent of assertions made in test setup code.

Link to repl or repo (highly encouraged)

Reproduction repo: https://github.com/h4l/jest-expect-assertions-bug

envinfo

  System:
    OS: macOS 10.14.4
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
  npmPackages:
    jest: 24.9.0 => 24.9.0
@ballercat
Copy link

Looks to be related to this issue as well #8297

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

@github-actions github-actions bot added the Stale label Feb 17, 2023
@github-actions
Copy link

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 Mar 19, 2023
@github-actions
Copy link

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 Apr 21, 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