Skip to content

[prefer-expect-assertions] Addition of an "ifPromisesUsed" option  #481

@erunion

Description

@erunion

I really like the prefer-expect-assertions rule, but requiring a test file to be covered in either expect.assertions(n) or expect.hasAssertions() calls when assertions aren't nested inside promises gets a little messy.

It would be rad to be able to have an ifPromisesUsed option on the rule that when enabled, would only throw the rule if:

  • The test case returns a Promise directly to Jest and
  • There are no expect() calls inside of the Promises resolve or reject methods.
test('should not trigger the rule because there is explicit expectation by itself', () => {
  expect(true).toBeTruthy();
});

test('should trigger the rule because there is an expectation inside of a Promise resolver', () => {
  expect.hasAssertions(); // expect.assertions(1);
  return methodThatShouldAPromise(done => {
    expect(true).toBeTruthy();
    done();
  });
});

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