-
Notifications
You must be signed in to change notification settings - Fork 248
Closed
Description
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();
});
});astorije