Testing Library
Testing Library test source rules from eslint-plugin-testing-library. Apply to TypeScript test sources that use any @testing-library/* package and detect Testing Library anti-patterns, container access, ByTestId overuse, missing await on async queries. AST-only; rules report only after a Testing Library import is present in the file.
Source: eslint-plugin-testing-library (MIT).
testing-library/await-async-events: Require awaiting async user-event methods (userEvent.click,userEvent.type, β¦) under the v14+ Promise-returning API.testing-library/await-async-queries: Require awaitingfindBy*andfindAllBy*queries.testing-library/await-async-utils: Require awaitingwaitFor,waitForElementToBeRemoved, and the other async Testing Library utilities.testing-library/consistent-data-testid: Validate JSXdata-testidattribute values against a regex pattern.testing-library/no-await-sync-events: Reject unnecessaryawaitbefore synchronous event helpers (fireEvent.click(...)).testing-library/no-await-sync-queries: Reject unnecessaryawaitbefore synchronous queries (getBy*,queryBy*).testing-library/no-container: Rejectcontainerdestructuring and DOM query methods on the render result.testing-library/no-debugging-utils: Rejectdebug,prettyDOM,logTestingPlaygroundURL, and related debugging utilities in committed tests.testing-library/no-dom-import: Reject direct@testing-library/domimports when a framework-specific package is installed.testing-library/no-global-regexp-flag-in-query: Reject global RegExp flags (/foo/g) inside query text matchers.testing-library/no-manual-cleanup: Reject manualcleanup()calls.testing-library/no-node-access: Reject direct DOM node traversal from query results (.parentElement,.firstChild,.children, β¦).testing-library/no-promise-in-fire-event: Reject Promise-producing expressions passed tofireEvent, sincefireEventis synchronous and the Promise is dropped.testing-library/no-render-in-lifecycle: Rejectrender(...)inside lifecycle hooks (beforeEach, etc.).testing-library/no-test-id-queries: Reject*ByTestIdqueries.testing-library/no-unnecessary-act: Reject unnecessaryact(...)wrappers around Testing Library helpers.testing-library/no-wait-for-multiple-assertions: Reject multiple assertions inside onewaitForcallback. Split into separatewaitFors so each retry boundary is narrow.testing-library/no-wait-for-side-effects: Reject side effects insidewaitForcallbacks,waitForretries the callback, so side effects fire repeatedly.testing-library/no-wait-for-snapshot: Reject snapshot assertions insidewaitFor.testing-library/prefer-explicit-assert: Require explicit assertions on the result of standalone queries.testing-library/prefer-find-by: PreferfindBy*overwaitForwrapping agetBy*.testing-library/prefer-implicit-assert: Avoid redundanttoBeInTheDocument()aroundgetBy*queries.testing-library/prefer-presence-queries: Match presence and absence assertions to the query variant that already encodes the same semantic:getBy*for presence (throws when missing),queryBy*for absence (returnsnullwhen missing).testing-library/prefer-query-by-disappearance: PreferqueryBy*insidewaitForElementToBeRemoved.testing-library/prefer-query-matchers: Prefer jest-dom document matchers (toBeVisible,toHaveTextContent, β¦) over generic equality checks on Testing Library queries.testing-library/prefer-screen-queries: Preferscreen.*over queries on the render-result object.testing-library/prefer-user-event: PreferuserEventoverfireEvent.testing-library/prefer-user-event-setup: PreferuserEvent.setup()(the v14+ instance pattern) over the staticuserEvent.*calls.testing-library/render-result-naming-convention: Require the variable assigned fromrender(...)to use one of the conventional names (view,result, β¦).
Last updated on