Skip to content

[prefer-expect-assertions] allow beforeEach(expect.hasAssertions) #876

@EvgenyOrekhov

Description

@EvgenyOrekhov

Recently I found out that instead of repeating expect.hasAssertions() in each test, you can have a single beforeEach(expect.hasAssertions) call at the top of the file.

It would be great if prefer-expect-assertions could detect file-level beforeEach(expect.hasAssertions) call and NOT give warnings in this case.

Current behavior:

beforeEach(expect.hasAssertions);

test("foo", () => {
  // Warning: Every test should have either `expect.assertions(<number of assertions>)`
  // or `expect.hasAssertions()` as its first expression
});
beforeEach(() => {
  expect.hasAssertions();
  someOtherFunction();
});

test("foo", () => {
  // Warning: Every test should have either `expect.assertions(<number of assertions>)`
  // or `expect.hasAssertions()` as its first expression
});

Expected behavior:

beforeEach(expect.hasAssertions);

test("foo", () => {
  // No warnings
});
beforeEach(() => {
  expect.hasAssertions();
  someOtherFunction();
});

test("foo", () => {
  // No warnings
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions