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

Tests are passing when afterAll() is placed inside a describe and throws #9368

Closed
aalexgabi opened this issue Jan 6, 2020 · 5 comments
Closed

Comments

@aalexgabi
Copy link

When executing this:

afterAll(() => {
  console.log('begun afterAll');
  throw new Error('This should fail');
  console.log('finished afterAll');
});

describe('describe', () => {
  test('test', () => {
    console.log('test');
  });
});

The test is failing:

% npx jest test/t.spec.js
 FAIL  test/t.spec.js
  ● Test suite failed to run

    Error: This should fail

      1 | afterAll(() => {
      2 |   console.log('begun afterAll');
    > 3 |   throw new Error('This should fail');
        |         ^
      4 |   console.log('finished afterAll');
      5 | });
      6 | 

      at Object.<anonymous> (test/t.spec.js:3:9)

  console.log test/t.spec.js:9
    test

  console.log test/t.spec.js:2
    begun afterAll

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.705s, estimated 1s
Ran all test suites matching /test\/t.spec.js/i.

This is the expected behavior but when I put the afterAll inside a describe:

describe('describe', () => {
  afterAll(() => {
    console.log('begun afterAll');
    throw new Error('This should fail');
    console.log('finished afterAll');
  });

  test('test', () => {
    console.log('test');
  });
});

The test passes:

% npx jest test/t.spec.js            
 PASS  test/t.spec.js
  describe
    ✓ test (3ms)

  console.log test/t.spec.js:9
    test

  console.log test/t.spec.js:3
    begun afterAll

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.628s, estimated 1s
Ran all test suites matching /test\/t.spec.js/i.

I am expecting the test to fail but it does not.

envinfo

% npx envinfo --preset jest
npx: installed 1 in 0.67s

  System:
    OS: Linux 5.3 Manjaro Linux
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 13.5.0 - /usr/bin/node
    npm: 6.13.4 - /usr/bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0 

Refs

#3785
#3266
#5884

@aalexgabi aalexgabi changed the title Tests are passing even when errors are thrown in afterAll() when inside a describe Tests are passing when afterAll() is placed inside a describe and throws Jan 6, 2020
@jayarjo
Copy link

jayarjo commented May 26, 2020

Any follow-up on this? I too encounter it in Jest 25.5.4. It actually led me to believe that my workaround for some vague problem was working, while it wasn't and exception in afterAll was simply swallowed (my afterAll is async - if it matters). I'd say HUGE problem! No idea how it managed to go under radar for so long.

Update: Just tried 26.0.1 - same thing.

@jayarjo
Copy link

jayarjo commented May 28, 2020

Switching to jest-circus fixes this one as well. See: #9882

@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 19, 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