From 20f23ad0810654ab046e7056560653c72274d50a Mon Sep 17 00:00:00 2001 From: Spencer Miskoviak <5247455+skovy@users.noreply.github.com> Date: Mon, 19 Sep 2022 07:49:12 -0700 Subject: [PATCH] feat(prefer-wait-for): remove rule (#648) BREAKING CHANGE: `prefer-wait-for` is now removed --- .github/ISSUE_TEMPLATE/propose_new_rule.yml | 2 +- README.md | 1 - docs/rules/prefer-wait-for.md | 74 - lib/rules/prefer-wait-for.ts | 214 -- tests/index.test.ts | 2 +- tests/lib/rules/prefer-wait-for.test.ts | 2258 ------------------- 6 files changed, 2 insertions(+), 2549 deletions(-) delete mode 100644 docs/rules/prefer-wait-for.md delete mode 100644 lib/rules/prefer-wait-for.ts delete mode 100644 tests/lib/rules/prefer-wait-for.test.ts diff --git a/.github/ISSUE_TEMPLATE/propose_new_rule.yml b/.github/ISSUE_TEMPLATE/propose_new_rule.yml index 8205d7d4..6af708cd 100644 --- a/.github/ISSUE_TEMPLATE/propose_new_rule.yml +++ b/.github/ISSUE_TEMPLATE/propose_new_rule.yml @@ -7,7 +7,7 @@ body: attributes: label: Name for new rule description: Suggest a name for the new rule that follows the [rule naming conventions](https://github.com/testing-library/eslint-plugin-testing-library/blob/main/CONTRIBUTING.md#rule-naming-conventions). - placeholder: prefer-wait-for + placeholder: prefer-find-by validations: required: true diff --git a/README.md b/README.md index f8186ca4..c7ea121d 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,6 @@ To enable this configuration use the `extends` property in your | [`prefer-query-by-disappearance`](./docs/rules/prefer-query-by-disappearance.md) | Suggest using `queryBy*` queries when waiting for disappearance | | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] ![marko-badge][] | | [`prefer-screen-queries`](./docs/rules/prefer-screen-queries.md) | Suggest using `screen` while querying | | ![dom-badge][] ![angular-badge][] ![react-badge][] ![vue-badge][] ![marko-badge][] | | [`prefer-user-event`](./docs/rules/prefer-user-event.md) | Suggest using `userEvent` over `fireEvent` for simulating user interactions | | | -| [`prefer-wait-for`](./docs/rules/prefer-wait-for.md) | Use `waitFor` instead of deprecated wait methods | 🔧 | | | [`render-result-naming-convention`](./docs/rules/render-result-naming-convention.md) | Enforce a valid naming for return value from `render` | | ![angular-badge][] ![react-badge][] ![vue-badge][] ![marko-badge][] | diff --git a/docs/rules/prefer-wait-for.md b/docs/rules/prefer-wait-for.md deleted file mode 100644 index 449548fd..00000000 --- a/docs/rules/prefer-wait-for.md +++ /dev/null @@ -1,74 +0,0 @@ -# Use `waitFor` instead of deprecated wait methods (`testing-library/prefer-wait-for`) - -`dom-testing-library` v7 released a new async util called `waitFor` which satisfies the use cases of `wait`, `waitForElement`, and `waitForDomChange` making them deprecated. - -## Rule Details - -This rule aims to use `waitFor` async util rather than previous deprecated ones. - -Deprecated `wait` async utils are: - -- `wait` -- `waitForElement` -- `waitForDomChange` - -> This rule will auto fix deprecated async utils for you, including the necessary empty callback for `waitFor`. This means `wait();` will be replaced with `waitFor(() => {});` - -Examples of **incorrect** code for this rule: - -```js -import { wait, waitForElement, waitForDomChange } from '@testing-library/dom'; -// this also works for const { wait, waitForElement, waitForDomChange } = require ('@testing-library/dom') - -const foo = async () => { - await wait(); - await wait(() => {}); - await waitForElement(() => {}); - await waitForDomChange(); - await waitForDomChange(mutationObserverOptions); - await waitForDomChange({ timeout: 100 }); -}; - -import * as tl from '@testing-library/dom'; -// this also works for const tl = require('@testing-library/dom') -const foo = async () => { - await tl.wait(); - await tl.wait(() => {}); - await tl.waitForElement(() => {}); - await tl.waitForDomChange(); - await tl.waitForDomChange(mutationObserverOptions); - await tl.waitForDomChange({ timeout: 100 }); -}; -``` - -Examples of **correct** code for this rule: - -```js -import { waitFor, waitForElementToBeRemoved } from '@testing-library/dom'; -// this also works for const { waitFor, waitForElementToBeRemoved } = require('@testing-library/dom') -const foo = async () => { - // new waitFor method - await waitFor(() => {}); - - // previous waitForElementToBeRemoved is not deprecated - await waitForElementToBeRemoved(() => {}); -}; - -import * as tl from '@testing-library/dom'; -// this also works for const tl = require('@testing-library/dom') -const foo = async () => { - // new waitFor method - await tl.waitFor(() => {}); - - // previous waitForElementToBeRemoved is not deprecated - await tl.waitForElementToBeRemoved(() => {}); -}; -``` - -## When Not To Use It - -When using dom-testing-library (or any other Testing Library relying on dom-testing-library) prior to v7. - -## Further Reading - -- [dom-testing-library v7 release](https://github.com/testing-library/dom-testing-library/releases/tag/v7.0.0) diff --git a/lib/rules/prefer-wait-for.ts b/lib/rules/prefer-wait-for.ts deleted file mode 100644 index 30cb93b7..00000000 --- a/lib/rules/prefer-wait-for.ts +++ /dev/null @@ -1,214 +0,0 @@ -import { TSESTree, ASTUtils } from '@typescript-eslint/utils'; - -import { createTestingLibraryRule } from '../create-testing-library-rule'; -import { - isImportSpecifier, - isMemberExpression, - findClosestCallExpressionNode, - isCallExpression, - isImportNamespaceSpecifier, - isObjectPattern, - isProperty, -} from '../node-utils'; - -export const RULE_NAME = 'prefer-wait-for'; -export type MessageIds = - | 'preferWaitForImport' - | 'preferWaitForMethod' - | 'preferWaitForRequire'; -type Options = []; - -const DEPRECATED_METHODS = ['wait', 'waitForElement', 'waitForDomChange']; - -export default createTestingLibraryRule({ - name: RULE_NAME, - meta: { - type: 'suggestion', - docs: { - description: 'Use `waitFor` instead of deprecated wait methods', - recommendedConfig: { - dom: false, - angular: false, - react: false, - vue: false, - marko: false, - }, - }, - messages: { - preferWaitForMethod: - '`{{ methodName }}` is deprecated in favour of `waitFor`', - preferWaitForImport: 'import `waitFor` instead of deprecated async utils', - preferWaitForRequire: - 'require `waitFor` instead of deprecated async utils', - }, - - fixable: 'code', - schema: [], - }, - defaultOptions: [], - - create(context, _, helpers) { - let addWaitFor = false; - - const reportRequire = (node: TSESTree.ObjectPattern) => { - context.report({ - node, - messageId: 'preferWaitForRequire', - fix(fixer) { - const excludedImports = [...DEPRECATED_METHODS, 'waitFor']; - - const newAllRequired = node.properties - .filter( - (s) => - isProperty(s) && - ASTUtils.isIdentifier(s.key) && - !excludedImports.includes(s.key.name) - ) - .map( - (s) => ((s as TSESTree.Property).key as TSESTree.Identifier).name - ); - - newAllRequired.push('waitFor'); - - return fixer.replaceText(node, `{ ${newAllRequired.join(',')} }`); - }, - }); - }; - - const reportImport = (node: TSESTree.ImportDeclaration) => { - context.report({ - node, - messageId: 'preferWaitForImport', - fix(fixer) { - const excludedImports = [...DEPRECATED_METHODS, 'waitFor']; - - // get all import names excluding all testing library `wait*` utils... - const newImports = node.specifiers - .map( - (specifier) => - isImportSpecifier(specifier) && - !excludedImports.includes(specifier.imported.name) && - specifier.imported.name - ) - .filter(Boolean) as string[]; - - // ... and append `waitFor` - newImports.push('waitFor'); - - // build new node with new imports and previous source value - const newNode = `import { ${newImports.join(',')} } from '${ - node.source.value - }';`; - - return fixer.replaceText(node, newNode); - }, - }); - }; - - const reportWait = (node: TSESTree.Identifier | TSESTree.JSXIdentifier) => { - context.report({ - node, - messageId: 'preferWaitForMethod', - data: { - methodName: node.name, - }, - fix(fixer) { - const callExpressionNode = findClosestCallExpressionNode(node); - if (!callExpressionNode) { - return null; - } - const [arg] = callExpressionNode.arguments; - const fixers = []; - - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (arg) { - // if method been fixed already had a callback - // then we just replace the method name. - fixers.push(fixer.replaceText(node, 'waitFor')); - - if (node.name === 'waitForDomChange') { - // if method been fixed is `waitForDomChange` - // then the arg received was options object so we need to insert - // empty callback before. - fixers.push(fixer.insertTextBefore(arg, '() => {}, ')); - } - } else { - // if wait method been fixed didn't have any callback - // then we replace the method name and include an empty callback. - let methodReplacement = 'waitFor(() => {})'; - - // if wait method used like `foo.wait()` then we need to keep the - // member expression to get `foo.waitFor(() => {})` - if ( - isMemberExpression(node.parent) && - ASTUtils.isIdentifier(node.parent.object) - ) { - methodReplacement = `${node.parent.object.name}.${methodReplacement}`; - } - const newText = methodReplacement; - - fixers.push(fixer.replaceText(callExpressionNode, newText)); - } - - return fixers; - }, - }); - }; - - return { - 'CallExpression > MemberExpression'(node: TSESTree.MemberExpression) { - const isDeprecatedMethod = - ASTUtils.isIdentifier(node.property) && - DEPRECATED_METHODS.includes(node.property.name); - if (!isDeprecatedMethod) { - // the method does not match a deprecated method - return; - } - if (!helpers.isNodeComingFromTestingLibrary(node)) { - // the method does not match from the imported elements from TL (even from custom) - return; - } - addWaitFor = true; - reportWait(node.property as TSESTree.Identifier); // compiler is not picking up correctly, it should have inferred it is an identifier - }, - 'CallExpression > Identifier'(node: TSESTree.Identifier) { - if (!DEPRECATED_METHODS.includes(node.name)) { - return; - } - - if (!helpers.isNodeComingFromTestingLibrary(node)) { - return; - } - addWaitFor = true; - reportWait(node); - }, - 'Program:exit'() { - if (!addWaitFor) { - return; - } - // now that all usages of deprecated methods were replaced, remove the extra imports - const testingLibraryNode = - helpers.getCustomModuleImportNode() ?? - helpers.getTestingLibraryImportNode(); - if (isCallExpression(testingLibraryNode)) { - const parent = - testingLibraryNode.parent as TSESTree.VariableDeclarator; - if (!isObjectPattern(parent.id)) { - // if there is no destructuring, there is nothing to replace - return; - } - reportRequire(parent.id); - } else if (testingLibraryNode) { - if ( - testingLibraryNode.specifiers.length === 1 && - isImportNamespaceSpecifier(testingLibraryNode.specifiers[0]) - ) { - // if we import everything, there is nothing to replace - return; - } - reportImport(testingLibraryNode); - } - }, - }; - }, -}); diff --git a/tests/index.test.ts b/tests/index.test.ts index 6e490f2b..49cf042f 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -8,7 +8,7 @@ import plugin from '../lib'; const execAsync = util.promisify(exec); const generateConfigs = () => execAsync(`npm run generate:configs`); -const numberOfRules = 27; +const numberOfRules = 26; const ruleNames = Object.keys(plugin.rules); // eslint-disable-next-line jest/expect-expect diff --git a/tests/lib/rules/prefer-wait-for.test.ts b/tests/lib/rules/prefer-wait-for.test.ts deleted file mode 100644 index d9dec019..00000000 --- a/tests/lib/rules/prefer-wait-for.test.ts +++ /dev/null @@ -1,2258 +0,0 @@ -import rule, { RULE_NAME } from '../../../lib/rules/prefer-wait-for'; -import { LIBRARY_MODULES } from '../../../lib/utils'; -import { createRuleTester } from '../test-utils'; - -const ruleTester = createRuleTester(); - -ruleTester.run(RULE_NAME, rule, { - valid: [ - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `import { waitFor, render } from '${libraryModule}'; - - async () => { - await waitFor(() => {}); - }`, - })), - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `const { waitFor, render } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}); - }`, - })), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitFor, render } from 'test-utils'; - - async () => { - await waitFor(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitFor, render } = require('test-utils'); - - async () => { - await waitFor(() => {}); - }`, - }, - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `import { waitForElementToBeRemoved, render } from '${libraryModule}'; - - async () => { - await waitForElementToBeRemoved(() => {}); - }`, - })), - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `const { waitForElementToBeRemoved, render } = require('${libraryModule}'); - - async () => { - await waitForElementToBeRemoved(() => {}); - }`, - })), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForElementToBeRemoved, render } from 'test-utils'; - - async () => { - await waitForElementToBeRemoved(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForElementToBeRemoved, render } = require('test-utils'); - - async () => { - await waitForElementToBeRemoved(() => {}); - }`, - }, - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `import * as testingLibrary from '${libraryModule}'; - - async () => { - await testingLibrary.waitForElementToBeRemoved(() => {}); - }`, - })), - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `const testingLibrary = require('${libraryModule}'); - - async () => { - await testingLibrary.waitForElementToBeRemoved(() => {}); - }`, - })), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import * as testingLibrary from 'test-utils'; - - async () => { - await testingLibrary.waitForElementToBeRemoved(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const testingLibrary = require('test-utils'); - - async () => { - await testingLibrary.waitForElementToBeRemoved(() => {}); - }`, - }, - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `import { render } from '${libraryModule}'; - import { waitForSomethingElse } from 'other-module'; - - async () => { - await waitForSomethingElse(() => {}); - }`, - })), - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `const { render } = require('${libraryModule}'); - const { waitForSomethingElse } = require('other-module'); - - async () => { - await waitForSomethingElse(() => {}); - }`, - })), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { render } from 'test-utils'; - import { waitForSomethingElse } from 'other-module'; - - async () => { - await waitForSomethingElse(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { render } = require('test-utils'); - const { waitForSomethingElse } = require('other-module'); - - async () => { - await waitForSomethingElse(() => {}); - }`, - }, - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `import * as testingLibrary from '${libraryModule}'; - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - })), - ...LIBRARY_MODULES.map((libraryModule) => ({ - code: `const testingLibrary = require('${libraryModule}'); - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - })), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import * as testingLibrary from 'test-utils'; - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const testingLibrary = require('test-utils'); - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - }, - { - code: `import { wait } from 'imNoTestingLibrary'; - - async () => { - await wait(); - }`, - }, - { - code: `const { wait } = require('imNoTestingLibrary'); - - async () => { - await wait(); - }`, - }, - { - code: `import * as foo from 'imNoTestingLibrary'; - - async () => { - await foo.wait(); - }`, - }, - { - code: `const foo = require('imNoTestingLibrary'); - - async () => { - await foo.wait(); - }`, - }, - { - code: `import * as foo from 'imNoTestingLibrary'; - cy.wait(); - `, - }, - { - code: `const foo = require('imNoTestingLibrary'); - cy.wait(); - `, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: ` - // case: aggressive reporting disabled - method named same as invalid method - // but not coming from Testing Library is valid - import { wait as testingLibraryWait } from 'test-utils' - import { wait } from 'somewhere-else' - - async () => { - await wait(); - } - `, - }, - { - // https://github.com/testing-library/eslint-plugin-testing-library/issues/145 - code: `import * as foo from 'imNoTestingLibrary'; - async function wait(): Promise { - // doesn't matter - } - - function callsWait(): void { - await wait(); - } - `, - }, - { - // https://github.com/testing-library/eslint-plugin-testing-library/issues/145 - code: `const foo = require('imNoTestingLibrary'); - async function wait(): Promise { - // doesn't matter - } - - function callsWait(): void { - await wait(); - } - `, - }, - ], - - invalid: [ - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { wait, render } from '${libraryModule}'; - - async () => { - await wait(); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { wait, render } = require('${libraryModule}'); - - async () => { - await wait(); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { wait, render } from 'test-utils'; - - async () => { - await wait(); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { wait, render } = require('test-utils'); - - async () => { - await wait(); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}); - }`, - }, - // namespaced wait should be fixed but not its import - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import * as testingLibrary from '${libraryModule}'; - - async () => { - await testingLibrary.wait(); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `import * as testingLibrary from '${libraryModule}'; - - async () => { - await testingLibrary.waitFor(() => {}); - }`, - } as const) - ), - // namespaced wait should be fixed but not its import - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const testingLibrary = require('${libraryModule}'); - - async () => { - await testingLibrary.wait(); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `const testingLibrary = require('${libraryModule}'); - - async () => { - await testingLibrary.waitFor(() => {}); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import * as testingLibrary from 'test-utils'; - - async () => { - await testingLibrary.wait(); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `import * as testingLibrary from 'test-utils'; - - async () => { - await testingLibrary.waitFor(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const testingLibrary = require('test-utils'); - - async () => { - await testingLibrary.wait(); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `const testingLibrary = require('test-utils'); - - async () => { - await testingLibrary.waitFor(() => {}); - }`, - }, - // namespaced waitForDomChange should be fixed but not its import - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import * as testingLibrary from '${libraryModule}'; - - async () => { - await testingLibrary.waitForDomChange({ timeout: 500 }); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `import * as testingLibrary from '${libraryModule}'; - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - } as const) - ), - // namespaced waitForDomChange should be fixed but not its import - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const testingLibrary = require('${libraryModule}'); - - async () => { - await testingLibrary.waitForDomChange({ timeout: 500 }); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `const testingLibrary = require('${libraryModule}'); - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import * as testingLibrary from 'test-utils'; - - async () => { - await testingLibrary.waitForDomChange({ timeout: 500 }); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `import * as testingLibrary from 'test-utils'; - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const testingLibrary = require('test-utils'); - - async () => { - await testingLibrary.waitForDomChange({ timeout: 500 }); - }`, - errors: [ - { - messageId: 'preferWaitForMethod', - line: 4, - column: 30, - }, - ], - output: `const testingLibrary = require('test-utils'); - - async () => { - await testingLibrary.waitFor(() => {}, { timeout: 500 }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { render, wait } from '${libraryModule}' - - async () => { - await wait(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { render, wait } = require('${libraryModule}'); - - async () => { - await wait(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { render, wait } from 'test-utils' - - async () => { - await wait(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { render, wait } = require('test-utils'); - - async () => { - await wait(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}); - }`, - }, - // this import doesn't have trailing semicolon but fixer adds it - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { render, wait, screen } from "${libraryModule}"; - - async () => { - await wait(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,screen,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - } as const) - ), - // this import doesn't have trailing semicolon but fixer adds it - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { render, wait, screen } from "${libraryModule}"; - - async () => { - await wait(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,screen,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { render, wait, screen } from "test-utils"; - - async () => { - await wait(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,screen,waitFor } from 'test-utils'; - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { render, wait, screen } = require('test-utils'); - - async () => { - await wait(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,screen,waitFor } = require('test-utils'); - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { render, waitForElement, screen } from '${libraryModule}' - - async () => { - await waitForElement(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,screen,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { render, waitForElement, screen } = require('${libraryModule}'); - - async () => { - await waitForElement(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,screen,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { render, waitForElement, screen } from 'test-utils' - - async () => { - await waitForElement(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,screen,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { render, waitForElement, screen } = require('test-utils'); - - async () => { - await waitForElement(() => {}); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,screen,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { waitForElement } from '${libraryModule}'; - - async () => { - await waitForElement(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from '${libraryModule}'; - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { waitForElement } = require('${libraryModule}'); - - async () => { - await waitForElement(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForElement } from 'test-utils'; - - async () => { - await waitForElement(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from 'test-utils'; - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForElement } = require('test-utils'); - - async () => { - await waitForElement(function cb() { - doSomething(); - }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('test-utils'); - - async () => { - await waitFor(function cb() { - doSomething(); - }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { waitForDomChange } from '${libraryModule}'; - - async () => { - await waitForDomChange(); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { waitForDomChange } = require('${libraryModule}'); - - async () => { - await waitForDomChange(); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForDomChange } from 'test-utils'; - - async () => { - await waitForDomChange(); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForDomChange } = require('test-utils'); - - async () => { - await waitForDomChange(); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { waitForDomChange } from '${libraryModule}'; - - async () => { - await waitForDomChange(mutationObserverOptions); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}, mutationObserverOptions); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { waitForDomChange } = require('${libraryModule}'); - - async () => { - await waitForDomChange(mutationObserverOptions); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}, mutationObserverOptions); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForDomChange } from 'test-utils'; - - async () => { - await waitForDomChange(mutationObserverOptions); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}, mutationObserverOptions); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForDomChange } = require('test-utils'); - - async () => { - await waitForDomChange(mutationObserverOptions); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}, mutationObserverOptions); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { waitForDomChange } from '${libraryModule}'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { waitForDomChange } = require('${libraryModule}'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForDomChange } from 'test-utils'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForDomChange } = require('test-utils'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { waitForDomChange, wait, waitForElement } from '${libraryModule}'; - import userEvent from '@testing-library/user-event'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 8, - column: 15, - }, - ], - output: `import { waitFor } from '${libraryModule}'; - import userEvent from '@testing-library/user-event'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { waitForDomChange, wait, waitForElement } = require('${libraryModule}'); - const userEvent = require('@testing-library/user-event'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 8, - column: 15, - }, - ], - output: `const { waitFor } = require('${libraryModule}'); - const userEvent = require('@testing-library/user-event'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForDomChange, wait, waitForElement } from 'test-utils'; - import userEvent from '@testing-library/user-event'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 8, - column: 15, - }, - ], - output: `import { waitFor } from 'test-utils'; - import userEvent from '@testing-library/user-event'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForDomChange, wait, waitForElement } = require('test-utils'); - const userEvent = require('@testing-library/user-event'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 8, - column: 15, - }, - ], - output: `const { waitFor } = require('test-utils'); - const userEvent = require('@testing-library/user-event'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { render, waitForDomChange, wait, waitForElement } from '${libraryModule}'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `import { render,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { render, waitForDomChange, wait, waitForElement } = require('${libraryModule}'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `const { render,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { render, waitForDomChange, wait, waitForElement } from 'test-utils'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `import { render,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { render, waitForDomChange, wait, waitForElement } = require('test-utils'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `const { render,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { waitForDomChange, wait, render, waitForElement } from '${libraryModule}'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `import { render,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { waitForDomChange, wait, render, waitForElement } = require('${libraryModule}'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `const { render,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { waitForDomChange, wait, render, waitForElement } from 'test-utils'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `import { render,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { waitForDomChange, wait, render, waitForElement } = require('test-utils'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 5, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 6, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 7, - column: 15, - }, - ], - output: `const { render,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `import { - waitForDomChange, - wait, - render, - waitForElement, - } from '${libraryModule}'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 9, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 10, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 11, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 12, - column: 15, - }, - ], - output: `import { render,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - code: `const { - waitForDomChange, - wait, - render, - waitForElement, - } = require('${libraryModule}'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 9, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 10, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 11, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 12, - column: 15, - }, - ], - output: `const { render,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `import { - waitForDomChange, - wait, - render, - waitForElement, - } from 'test-utils'; - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 9, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 10, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 11, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 12, - column: 15, - }, - ], - output: `import { render,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - code: `const { - waitForDomChange, - wait, - render, - waitForElement, - } = require('test-utils'); - - async () => { - await waitForDomChange({ timeout: 5000 }); - await waitForElement(); - await wait(); - await wait(() => { doSomething() }); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 9, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 10, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 11, - column: 15, - }, - { - messageId: 'preferWaitForMethod', - line: 12, - column: 15, - }, - ], - output: `const { render,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}, { timeout: 5000 }); - await waitFor(() => {}); - await waitFor(() => {}); - await waitFor(() => { doSomething() }); - }`, - }, - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - // if already importing waitFor then it's not imported twice - code: `import { wait, waitFor, render } from '${libraryModule}'; - - async () => { - await wait(); - await waitFor(someCallback); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,waitFor } from '${libraryModule}'; - - async () => { - await waitFor(() => {}); - await waitFor(someCallback); - }`, - } as const) - ), - ...LIBRARY_MODULES.map( - (libraryModule) => - ({ - // if already importing waitFor then it's not imported twice - code: `const { wait, waitFor, render } = require('${libraryModule}'); - - async () => { - await wait(); - await waitFor(someCallback); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,waitFor } = require('${libraryModule}'); - - async () => { - await waitFor(() => {}); - await waitFor(someCallback); - }`, - } as const) - ), - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - // if already importing waitFor then it's not imported twice - code: `import { wait, waitFor, render } from 'test-utils'; - - async () => { - await wait(); - await waitFor(someCallback); - }`, - errors: [ - { - messageId: 'preferWaitForImport', - line: 1, - column: 1, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `import { render,waitFor } from 'test-utils'; - - async () => { - await waitFor(() => {}); - await waitFor(someCallback); - }`, - }, - { - settings: { - 'testing-library/utils-module': 'test-utils', - }, - // if already importing waitFor then it's not imported twice - code: `const { wait, waitFor, render } = require('test-utils'); - - async () => { - await wait(); - await waitFor(someCallback); - }`, - errors: [ - { - messageId: 'preferWaitForRequire', - line: 1, - column: 7, - }, - { - messageId: 'preferWaitForMethod', - line: 4, - column: 15, - }, - ], - output: `const { render,waitFor } = require('test-utils'); - - async () => { - await waitFor(() => {}); - await waitFor(someCallback); - }`, - }, - ], -});