Skip to content

Commit

Permalink
test(no-wait-for-empty-callback): increase rule coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Belco90 committed Mar 16, 2021
1 parent 908fa2d commit 7ec46c0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/detect-testing-library-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,21 @@ export function detectTestingLibraryUtils<
* coming from Testing Library will be considered as valid.
*/
const isAsyncUtil: IsAsyncUtilFn = (node, validNames) => {
return isTestingLibraryUtil(node, (identifierNodeName) => {
if (validNames && validNames.length > 0) {
return (validNames as string[]).includes(identifierNodeName);
return isTestingLibraryUtil(
node,
(identifierNodeName, originalNodeName) => {
if (validNames && validNames.length > 0) {
return (
(validNames as string[]).includes(identifierNodeName) ||
(validNames as string[]).includes(originalNodeName)
);
}
return (
ASYNC_UTILS.includes(identifierNodeName) ||
ASYNC_UTILS.includes(originalNodeName)
);
}
return ASYNC_UTILS.includes(identifierNodeName);
});
);
};

/**
Expand Down
52 changes: 52 additions & 0 deletions tests/lib/rules/no-wait-for-empty-callback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ ruleTester.run(RULE_NAME, rule, {
{
code: `wait(() => {})`,
},
{
code: `wait(noop)`,
},
{
settings: { 'testing-library/utils-module': 'test-utils' },
code: `
import { waitFor } from 'somewhere-else'
waitFor(() => {})
`,
},
{
settings: { 'testing-library/utils-module': 'test-utils' },
code: `
import { waitFor as renamedWaitFor } from '@testing-library/react'
import { waitFor } from 'somewhere-else'
waitFor(() => {})
`,
},
],

invalid: [
Expand All @@ -45,6 +63,40 @@ ruleTester.run(RULE_NAME, rule, {
},
],
})),
...ALL_WAIT_METHODS.map((m) => ({
settings: { 'testing-library/utils-module': 'test-utils' },
code: `
import { ${m} } from 'test-utils';
${m}(() => {});
`,
errors: [
{
line: 3,
column: 16 + m.length,
messageId: 'noWaitForEmptyCallback',
data: {
methodName: m,
},
},
],
})),
...ALL_WAIT_METHODS.map((m) => ({
settings: { 'testing-library/utils-module': 'test-utils' },
code: `
import { ${m} as renamedAsyncUtil } from 'test-utils';
renamedAsyncUtil(() => {});
`,
errors: [
{
line: 3,
column: 32,
messageId: 'noWaitForEmptyCallback',
data: {
methodName: 'renamedAsyncUtil',
},
},
],
})),
...ALL_WAIT_METHODS.map((m) => ({
code: `${m}((a, b) => {})`,
errors: [
Expand Down

0 comments on commit 7ec46c0

Please sign in to comment.