Skip to content

[prefer-expect-assertions]: ensure expect.assertions is used when an expect is found to be within a loop #540

@benmonro

Description

@benmonro

It would be nice to have a lint rule that enforced a length check or use of expect.assertions when an expect call is found inside a loop.

for example:

for(let thing in things) {
  expect(thing).toBe("2");
}

would report an error

but this would not:

expect.assertions(4);

for(let thing in things) {
  expect(thing).toBe("2");
}

nor would this:

expect(things).toHaveLength(4);

for(let thing in things) {
  expect(thing).toBe("2");
}

Main goal here is to prevent false positive tests if things is an empty list.

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