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

assertions in beforeAll counted in first test in suite #5887

Closed
nazreen opened this issue Mar 28, 2018 · 7 comments
Closed

assertions in beforeAll counted in first test in suite #5887

nazreen opened this issue Mar 28, 2018 · 7 comments

Comments

@nazreen
Copy link

nazreen commented Mar 28, 2018

Do you want to request a feature or report a bug?
Report bug
What is the current behavior?
I have a beforeAll that has 3 assertions in it to ensure that everything is setup for the upcoming tests.
In my first test, because it is async, I use expect.assertions(5)
That test fails because it received 8 assertion calls.
If I remove the assertions in beforeAll, the test passes.

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

  1. Create test suite with beforeAll containing a single assertion that passes
  2. Create a test with expect.assertions(2)
  3. In the same test add another assertion that will pass

What is the expected behavior?
Test passes
Please provide your exact Jest configuration
Jest 21.2.1 inside of create-react-app

Run npx envinfo --preset jest in your project directory and paste the
results here

System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Binaries:
Node: 8.1.4
Yarn: 0.24.6
npm: 5.6.0
npmPackages:
jest:
wanted: ^21.2.1
installed: 21.2.1

@rafaelramalho19
Copy link
Contributor

Are you sure this is happening? Am I doing something different from you?

/**
 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

async function asyncFunction() {
  return 1;
}

beforeAll(() => {
  expect(1).toEqual(1);
});

test('asserts', () => {
  expect.assertions(2);

  asyncFunction().then(stuff => {
    expect(stuff).toEqual(1);
  });
});

@SimenB
Copy link
Member

SimenB commented Mar 29, 2018

@rafaelramalho19 make sure to return the promise. No idea of it changes anything (I'm on mobile now)

@rafaelramalho19
Copy link
Contributor

@SimenB Doesn't change anything, but yeah, I usually return the promise :)

@SimenB
Copy link
Member

SimenB commented Apr 14, 2018

This needs a reproduction. The best wouldbe a repo we can pull down to test

@thymikee
Copy link
Collaborator

OP is using Jest 21. This was most likely fixed by #4498. Closing.

@nazreen
Copy link
Author

nazreen commented Apr 16, 2018

@thymikee you're right, I am using 21.2.1
Thank you. I will update.

@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 May 12, 2021
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

4 participants