Skip to content

Commit

Permalink
fix(valid-expect): error on missing async matchers (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Jan 13, 2018
1 parent 6960e93 commit 16889bb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/rules/valid-expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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');
```
30 changes: 30 additions & 0 deletions rules/__tests__/valid_expect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
},
],
},
],
});
9 changes: 8 additions & 1 deletion rules/valid_expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down

0 comments on commit 16889bb

Please # to comment.