diff --git a/src/rules/__tests__/valid-expect-in-promise.test.ts b/src/rules/__tests__/valid-expect-in-promise.test.ts index a91cb516c..0a9b3deaa 100644 --- a/src/rules/__tests__/valid-expect-in-promise.test.ts +++ b/src/rules/__tests__/valid-expect-in-promise.test.ts @@ -51,6 +51,13 @@ ruleTester.run('valid-expect-in-promise', rule, { }); }); `, + dedent` + xtest('it1', function() { + return somePromise.catch(function() { + expect(someThing).toEqual(true); + }); + }); + `, dedent` it('it1', function() { return somePromise.then(function() { @@ -152,7 +159,16 @@ ruleTester.run('valid-expect-in-promise', rule, { const promise = something().then(value => { expect(value).toBe('red'); }); - + + return promise; + }); + `, + dedent` + test.only('later return', () => { + const promise = something().then(value => { + expect(value).toBe('red'); + }); + return promise; }); `, @@ -300,6 +316,16 @@ ruleTester.run('valid-expect-in-promise', rule, { `, errors: [{ column: 3, endColumn: 5, messageId: 'returnPromise' }], }, + { + code: dedent` + xtest('it1', function() { + somePromise.catch(function() { + expect(someThing).toEqual(true) + }) + }) + `, + errors: [{ column: 3, endColumn: 5, messageId: 'returnPromise' }], + }, { code: dedent` it('it1', function() { @@ -374,5 +400,27 @@ ruleTester.run('valid-expect-in-promise', rule, { `, errors: [{ column: 9, endColumn: 5, messageId: 'returnPromise' }], }, + { + code: dedent` + fit('it1', () => { + somePromise.then(() => { + doSomeOperation(); + expect(someThing).toEqual(true); + }) + }); + `, + errors: [{ column: 3, endColumn: 5, messageId: 'returnPromise' }], + }, + { + code: dedent` + it.skip('it1', () => { + somePromise.then(() => { + doSomeOperation(); + expect(someThing).toEqual(true); + }) + }); + `, + errors: [{ column: 3, endColumn: 5, messageId: 'returnPromise' }], + }, ], }); diff --git a/src/rules/valid-expect-in-promise.ts b/src/rules/valid-expect-in-promise.ts index 0b9bbb01e..8466b2ccb 100644 --- a/src/rules/valid-expect-in-promise.ts +++ b/src/rules/valid-expect-in-promise.ts @@ -6,12 +6,12 @@ import { import { FunctionExpression, KnownCallExpression, - TestCaseName, createRule, getAccessorValue, isExpectMember, isFunction, isSupportedAccessor, + isTestCaseCall, } from './utils'; type MessageIds = 'returnPromise'; @@ -95,16 +95,13 @@ const isPromiseReturnedLater = ( ); }; -const isTestFunc = (node: TSESTree.Node) => - node.type === AST_NODE_TYPES.CallExpression && - isSupportedAccessor(node.callee) && - ([TestCaseName.it, TestCaseName.test] as string[]).includes( - getAccessorValue(node.callee), - ); - const findTestFunction = (node: TSESTree.Node | undefined) => { while (node) { - if (isFunction(node) && node.parent && isTestFunc(node.parent)) { + if ( + isFunction(node) && + node.parent?.type === AST_NODE_TYPES.CallExpression && + isTestCaseCall(node.parent) + ) { return node; }