diff --git a/rules/__tests__/valid_expect_in_promise.test.js b/rules/__tests__/valid_expect_in_promise.test.js index f9ee77c48..79abe4ce7 100644 --- a/rules/__tests__/valid_expect_in_promise.test.js +++ b/rules/__tests__/valid_expect_in_promise.test.js @@ -3,7 +3,12 @@ const RuleTester = require('eslint').RuleTester; const rules = require('../..').rules; -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + parserOptions: { + ecmaVersion: 8, + }, +}); + const expectedMsg = 'Promise should be returned to test its fulfillment or rejection'; @@ -20,7 +25,6 @@ ruleTester.run('valid-expect-in-promise', rules['valid-expect-in-promise'], { message: expectedMsg, }, ], - parserOptions: { ecmaVersion: 6 }, }, { code: @@ -104,11 +108,7 @@ ruleTester.run('valid-expect-in-promise', rules['valid-expect-in-promise'], { ], valid: [ - { - code: - 'it("it1", () => { return somePromise.then(() => {expect(someThing).toEqual(true)})})', - parserOptions: { sourceType: 'module' }, - }, + 'it("it1", () => { return somePromise.then(() => {expect(someThing).toEqual(true)})})', 'it("it1", function() { return somePromise.catch(' + 'function() {expect(someThing).toEqual(true)})})', @@ -131,5 +131,14 @@ ruleTester.run('valid-expect-in-promise', rules['valid-expect-in-promise'], { 'function() { /*rejection*/ expect(someThing).toEqual(true)})})', 'it("it1", function() { return somePromise.then()})', + + 'it("it1", async () => { await Promise.resolve().then(' + + 'function() {expect(someThing).toEqual(true)})})', + + 'it("it1", async () => ' + + '{ await somePromise.then(() => {expect(someThing).toEqual(true)})})', + + 'it("it1", async () => { await getSomeThing().getPromise().then(' + + 'function() {expect(someThing).toEqual(true)})})', ], }); diff --git a/rules/valid_expect_in_promise.js b/rules/valid_expect_in_promise.js index b1eceeaec..3d8b3a033 100644 --- a/rules/valid_expect_in_promise.js +++ b/rules/valid_expect_in_promise.js @@ -45,7 +45,6 @@ const verifyExpectWithReturn = (argument, node, context) => { if ( argument && isFunction(argument.type) && - //$FlowFixMe isBodyCallExpression(argument.body) ) { const calleeInThenOrCatch = argument.body.body[0].expression.callee.object; @@ -57,18 +56,21 @@ const verifyExpectWithReturn = (argument, node, context) => { } }; +const isAwaitExpression = node => { + return node.parent.parent && node.parent.parent.type == 'AwaitExpression'; +}; + module.exports = context => { return { MemberExpression(node) { if ( node.type == 'MemberExpression' && isThenOrCatch(node) && - node.parent.type == 'CallExpression' + node.parent.type == 'CallExpression' && + !isAwaitExpression(node) ) { const parent = node.parent; - // $FlowFixMe const arg1 = parent.arguments[0]; - // $FlowFixMe const arg2 = parent.arguments[1]; // then block can have two args, fulfillment & rejection