You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Can not use toHaveTextContent because it doesn't match exact text// eslint-disable-next-line jest-dom/prefer-to-have-text-contentexpect(screen.getByTestId('location').textContent).toBe('/');
What you did:
I wanted to ensure that the tested value is exactly the value I pass to assertion.
What happened:
Eslint rule warns to use toHaveTextContent. Unfortunately, that change is also changing the behavior.
Problem description:
I believe everything is clear from the above examples and explanations. The jest-dom/prefer-to-have-text-content rule forces me to change my code to a version that doesn't fulfill my requirements.
Suggested solution:
The rule should only be triggered if the assertion toContain or similar is used.
Extend toHaveTextContent with exact option. Or add toBeTextContent.
The text was updated successfully, but these errors were encountered:
Since toBe, toEqual, and toStrictEqual are exact matchers the autofix should ideally use a regex like this - it actually seems we try to do something like that but for toContain and toMatch; it might be that these logics just need inverting? (and it could be this came from the matcher originally being exact then was later changed)
eslint-plugin-jest-dom
version: 5.1.0node
version: 18.14.2npm
version: yarn 3Relevant code or config
What I wanted to use
What I'm forced to use:
What you did:
I wanted to ensure that the tested value is exactly the value I pass to assertion.
What happened:
Eslint rule warns to use
toHaveTextContent
. Unfortunately, that change is also changing the behavior.Problem description:
I believe everything is clear from the above examples and explanations. The
jest-dom/prefer-to-have-text-content
rule forces me to change my code to a version that doesn't fulfill my requirements.Suggested solution:
The rule should only be triggered if the assertion
toContain
or similar is used.Extend
toHaveTextContent
with exact option. Or addtoBeTextContent
.The text was updated successfully, but these errors were encountered: