diff --git a/docs/rules/valid-expect.md b/docs/rules/valid-expect.md index 83249b63d..b01785ddc 100644 --- a/docs/rules/valid-expect.md +++ b/docs/rules/valid-expect.md @@ -32,6 +32,7 @@ expect().toEqual('something'); expect('something', 'else'); expect('something'); expect(true).toBeDefined; +expect(Promise.resolve('hello')).resolves; ``` The following patterns are not warnings: @@ -40,4 +41,5 @@ The following patterns are not warnings: expect('something').toEqual('something'); expect([1, 2, 3]).toEqual([1, 2, 3]); expect(true).toBeDefined(); +expect(Promise.resolve('hello')).resolves.toEqual('hello'); ``` diff --git a/rules/__tests__/valid_expect.test.js b/rules/__tests__/valid_expect.test.js index 1c6be5e95..ed74b6463 100644 --- a/rules/__tests__/valid_expect.test.js +++ b/rules/__tests__/valid_expect.test.js @@ -101,5 +101,35 @@ ruleTester.run('valid-expect', rules['valid-expect'], { }, ], }, + { + code: 'expect(true).resolves;', + errors: [ + { + endColumn: 22, + column: 14, + message: '"resolves" needs to call a matcher.', + }, + ], + }, + { + code: 'expect(true).rejects;', + errors: [ + { + endColumn: 21, + column: 14, + message: '"rejects" needs to call a matcher.', + }, + ], + }, + { + code: 'expect(true).not;', + errors: [ + { + endColumn: 17, + column: 14, + message: '"not" needs to call a matcher.', + }, + ], + }, ], }); diff --git a/rules/valid_expect.js b/rules/valid_expect.js index 1b37e3ed4..401c013b3 100644 --- a/rules/valid_expect.js +++ b/rules/valid_expect.js @@ -83,11 +83,18 @@ module.exports = context => { // matcher was not called if (grandParent.type === 'ExpressionStatement') { + let message; + if (expectProperties.indexOf(propertyName) > -1) { + message = `"${propertyName}" needs to call a matcher.`; + } else { + message = `"${propertyName}" was not called.`; + } + context.report({ // For some reason `endColumn` isn't set in tests if `loc` is not // added loc: parentProperty.loc, - message: `"${propertyName}" was not called.`, + message, node: parentProperty, }); }