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

[BUG] failure in BeforeEach does not block to run next BeforeEach block #8806

Closed
eLeontev opened this issue Sep 9, 2021 · 2 comments
Closed
Assignees

Comments

@eLeontev
Copy link

eLeontev commented Sep 9, 2021

Context:

  • Playwright Version: 1.14.1
  • Playwright/test Version: 1.14.1
  • Operating System: Windows
  • Node.js version: 14.17.1
  • Browser: -
  • Extra: default startup with npx playwright test and TypeScript

Code Snippet

import { expect, test } from '@playwright/test';

const bfeWithFailure = () => {
    throw new Error('123');
};

const bfeWithLog = () => console.log('should not be called');

test.describe.only('test', () => {
    test.beforeEach(bfeWithFailure);

    test.beforeEach(bfeWithLog);

    test('should not be called', () => {
        expect(1).toBe(1);
    });
});

Describe the bug

  1. Prepare the flow with unhandled error in the first beforeEach block
  2. Run test example

Actual result: bfeWithLog is called.
Expected result: bfeWithLog is not called.

@eLeontev
Copy link
Author

eLeontev commented Sep 10, 2021

Update: Looks like I missed to put any other test frameworks results.
In Jest(tested with: 26.5.3) the behavior the same even if couple of tickets were directly addressed to beforeAll with async callback.

Link to the issue: jestjs/jest#8688

Jest behavior (checked with all hooks - behavior the same):
image

@JoelEinbinder
Copy link
Contributor

It looks like our current behavior matches jest/jasmine. What you are describing is mocha style, where the failing hook stops the next hook from running. That gets tricky when you have a pattern like

before(() => {
 // set up something important
});
after(() => {
 // throw an error
});
after(() => {
 // tear down the important thing
});

The first failing after causes the second not to run, but it might be very important that it runs. There are pros and cons of each approach, so let's stick with what we have.

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

No branches or pull requests

3 participants