Skip to content

Commit

Permalink
Handle resolves and rejects on expect
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 17, 2017
1 parent 232681f commit 458b40c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ ruleTester.run('valid-expect', rules['valid-expect'], {
'expect(true).toBeDefined();',
'expect([1, 2, 3]).toEqual([1, 2, 3]);',
'expect(undefined).not.toBeDefined();',
'expect(Promise.resolve(2)).resolves.toBeDefined();',
'expect(Promise.reject(2)).rejects.toBeDefined();',
],

invalid: [
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin-jest/src/rules/valid-expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import type {EslintContext, CallExpression} from './types';

const expectProperties = ['not', 'resolves', 'rejects'];

module.exports = (context: EslintContext) => {
return {
CallExpression(node: CallExpression) {
Expand Down Expand Up @@ -45,7 +47,7 @@ module.exports = (context: EslintContext) => {
// a property is accessed, get the next node
if (grandParentType === 'MemberExpression') {
// `not` is used, just get the next one
if (propertyName === 'not') {
if (expectProperties.indexOf(propertyName) > -1) {
/* $FlowFixMe */
propertyName = node.parent.parent.property.name;
grandParentType = node.parent.parent.parent.type;
Expand Down

0 comments on commit 458b40c

Please sign in to comment.