Skip to content

Commit

Permalink
test: add missing dependencies test for FunctionExpression syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Newbie012 committed Apr 2, 2024
1 parent a9648ba commit eaf18e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,24 @@ ruleTester.run('exhaustive-deps', rule, {
},
],
},
{
name: 'should fail if queryFn is invalid while using FunctionExpression syntax',
code: normalizeIndent`
const id = 1;
useQuery({
queryKey: [],
queryFn() {
Promise.resolve(id)
}
})
`,
errors: [
{
messageId: 'missingDeps',
data: { deps: 'id' },
},
],
},
],
})
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export const rule = createRule({
scopeManager === null ||
queryKey === undefined ||
queryFn === undefined ||
queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression
![
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionExpression,
].includes(queryFn.value.type)
) {
return
}
Expand Down

0 comments on commit eaf18e7

Please sign in to comment.