diff --git a/lib/rules/expect-matcher.js b/lib/rules/expect-matcher.js index d200717..39b6f68 100644 --- a/lib/rules/expect-matcher.js +++ b/lib/rules/expect-matcher.js @@ -9,8 +9,13 @@ module.exports = function (context) { CallExpression: function (node) { if (node.callee.name === 'expect') { // matcher was not called - if (node.parent && node.parent.parent && node.parent.parent.type !== 'CallExpression' && - node.parent.parent.type !== 'MemberExpression') { + if ( + node.parent && + node.parent.parent && + (node.parent.type !== 'MemberExpression' || + (node.parent.parent.type !== 'CallExpression' && + node.parent.parent.type !== 'MemberExpression')) + ) { context.report({ message: 'Expect must have a corresponding matcher call.', node diff --git a/test/rules/expect-matcher.js b/test/rules/expect-matcher.js index 17cb203..9d9a837 100644 --- a/test/rules/expect-matcher.js +++ b/test/rules/expect-matcher.js @@ -3,14 +3,15 @@ var rule = require('../../lib/rules/expect-matcher') var RuleTester = require('eslint').RuleTester -var eslintTester = new RuleTester() +var eslintTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } }) eslintTester.run('expect-matcher', rule, { valid: [ 'expect("something").toEqual("else");', 'expect(true).toBeDefined();', 'expect([1, 2, 3]).toEqual([1, 2, 3]);', - 'expect(undefined).not.toBeDefined();' + 'expect(undefined).not.toBeDefined();', + 'it("something", () => expect(null).toBeFalsy());' ], invalid: [ @@ -37,6 +38,14 @@ eslintTester.run('expect-matcher', rule, { message: 'Expect must have a corresponding matcher call.' } ] + }, + { + code: 'it("something", () => expect(null));', + errors: [ + { + message: 'Expect must have a corresponding matcher call.' + } + ] } ] })