Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/rules/__tests__/valid-expect-in-promise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ ruleTester.run('valid-expect-in-promise', rule, {
});
});
`,
dedent`
it('it1', function () {
Promise.resolve().then(/*fulfillment*/ function () {
}, undefined, /*rejection*/ function () {
expect(someThing).toEqual(true)
})
});
`,
dedent`
it('it1', function () {
return Promise.resolve().then(function () {
Expand Down
4 changes: 3 additions & 1 deletion src/rules/no-mocks-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const mocksDirName = '__mocks__';
const isMockPath = (path: string) =>
path.split(posix.sep).includes(mocksDirName);

const isMockImportLiteral = (expression: TSESTree.Expression): boolean =>
const isMockImportLiteral = (
expression: TSESTree.CallExpressionArgument,
): boolean =>
isStringNode(expression) && isMockPath(getStringValue(expression));

export default createRule({
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-test-return-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
isTestCaseCall,
} from './utils';

const getBody = (args: TSESTree.Expression[]) => {
const getBody = (args: TSESTree.CallExpressionArgument[]) => {
const [, secondArg] = args;

if (
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
isTestCaseCall,
} from './utils';

function isEmptyFunction(node: TSESTree.Expression) {
function isEmptyFunction(node: TSESTree.CallExpressionArgument) {
if (!isFunction(node)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/valid-describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { createRule, getNodeName, isDescribeCall, isFunction } from './utils';

const paramsLocation = (
params: TSESTree.Expression[] | TSESTree.Parameter[],
params: TSESTree.CallExpressionArgument[] | TSESTree.Parameter[],
) => {
const [first] = params;
const last = params[params.length - 1];
Expand Down
10 changes: 2 additions & 8 deletions src/rules/valid-expect-in-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ const isParentThenOrPromiseReturned = (
node.type === AST_NODE_TYPES.ReturnStatement ||
isPromiseReturnedLater(node, testFunctionBody);

type PromiseCallbacks = [
TSESTree.Expression | undefined,
TSESTree.Expression | undefined,
];

const verifyExpectWithReturn = (
promiseCallbacks: PromiseCallbacks,
promiseCallbacks: Array<TSESTree.CallExpressionArgument | undefined>,
node: CalledKnownMemberExpression<'then' | 'catch'>,
context: RuleContext,
testFunctionBody: TSESTree.Statement[],
Expand Down Expand Up @@ -187,14 +182,13 @@ export default createRule<unknown[], MessageIds>({
}

const testFunctionBody = body.body;
const [fulfillmentCallback, rejectionCallback] = node.arguments;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a fix (i.e. released as a patch?)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Na, this is just a refactor as it doesn't actually change the behaviour: since we pick these two items out of the array only to then make a new array out of them which we pass through to a function.

So .slice(0, 2) should be functionally equivalent as that selects the first two items in the node.arguments array.


// then block can have two args, fulfillment & rejection
// then block can have one args, fulfillment
// catch block can have one args, rejection
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
verifyExpectWithReturn(
[fulfillmentCallback, rejectionCallback],
node.arguments.slice(0, 2),
node.callee,
context,
testFunctionBody,
Expand Down
Loading