From 60919f6c45173fecddd17799da0e5380a263b8c4 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Tue, 6 Nov 2018 23:31:28 +0100 Subject: [PATCH] fix(valid-expect-in-promise): fix type exception Fixes #195 --- rules/__tests__/valid-expect-in-promise.test.js | 9 +++++++++ rules/valid-expect-in-promise.js | 1 + 2 files changed, 10 insertions(+) diff --git a/rules/__tests__/valid-expect-in-promise.test.js b/rules/__tests__/valid-expect-in-promise.test.js index 32e294c61..563222439 100644 --- a/rules/__tests__/valid-expect-in-promise.test.js +++ b/rules/__tests__/valid-expect-in-promise.test.js @@ -182,6 +182,15 @@ ruleTester.run('valid-expect-in-promise', rule, { ], valid: [ + ` + it('it1', () => new Promise((done) => { + test() + .then(() => { + expect(someThing).toEqual(true); + done(); + }); + })); + `, ` it('it1', () => { return somePromise.then(() => { diff --git a/rules/valid-expect-in-promise.js b/rules/valid-expect-in-promise.js index 041282807..dc8ab9b75 100644 --- a/rules/valid-expect-in-promise.js +++ b/rules/valid-expect-in-promise.js @@ -88,6 +88,7 @@ const getTestFunction = node => { const isParentThenOrPromiseReturned = (node, testFunctionBody) => { return ( testFunctionBody.type === 'CallExpression' || + testFunctionBody.type === 'NewExpression' || node.parent.parent.type === 'ReturnStatement' || isPromiseReturnedLater(node, testFunctionBody) || isThenOrCatch(node.parent.parent)