We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user.type
https://codesandbox.io/p/sandbox/userevent-dom-djcc7b
:valid
invalid
Relevant code:
const css = ` input.test-input:valid { color: #ffffff; } input.test-input:invalid { color: #000000; } `; test("Test", async () => { const user = userEvent.setup(); render( <> <style>{css}</style> <input data-testid="element" class="test-input" type="text" pattern="must-match-this" value="must-match-this" /> </>, ); await user.type(screen.getByTestId("element"), "aaa"); expect(screen.getByTestId("element")).toHaveStyle("color: rgb(0, 0, 0)"); // Fails });
The input element should now have an invalid state.
The input element still have a valid state
14.5.2
Testing Library framework: @testing-library/react@14.1.2
@testing-library/react@14.1.2
Test environment: vitest@1.1.1
vitest@1.1.1
DOM implementation: jsdom@23.0.1
jsdom@23.0.1
user-event
If I remove the user.type line and change the initial value to mismatch the pattern, the style test would pass.
const css = ` input.test-input:valid { color: #ffffff; } input.test-input:invalid { color: #000000; } `; test("Test", async () => { const user = userEvent.setup(); render( <> <style>{css}</style> <input data-testid="element" class="test-input" type="text" pattern="must-match-this" value="must-match-thisaaa" /> </>, ); expect(screen.getByTestId("element")).toHaveStyle("color: rgb(0, 0, 0)"); // succeeds });
If I have an initially matched value, but set it to a mismatching value from container, the test also succeeds:
const css = ` input.test-input:valid { color: #ffffff; } input.test-input:invalid { color: #000000; } `; test("Test", async () => { const user = userEvent.setup(); const {container} = render( <> <style>{css}</style> <input data-testid="element" class="test-input" type="text" pattern="must-match-this" value="must-match-this" /> </>, ); const input = container.querySelector("input.test-input"); input.value = 'must-match-thisaaa'; expect(screen.getByTestId("element")).toHaveStyle("color: rgb(0, 0, 0)"); // succeeds });
But waitFor won't help:
waitFor
const css = ` input.test-input:valid { color: #ffffff; } input.test-input:invalid { color: #000000; } `; test("Test", async () => { const user = userEvent.setup(); const {container} = render( <> <style>{css}</style> <input data-testid="element" class="test-input" type="text" pattern="must-match-this" value="must-match-this" /> </>, ); const input = container.querySelector("input.test-input"); await user.type(screen.getByTestId("element"), "aaa"); await waitFor(() => expect(screen.getByTestId("element")).toHaveStyle("color: rgb(0, 0, 0)")); // fails });
The text was updated successfully, but these errors were encountered:
Closing this as duplicate of #801
Sorry, something went wrong.
No branches or pull requests
Reproduction example
https://codesandbox.io/p/sandbox/userevent-dom-djcc7b
Prerequisites
:valid
/invalid
pseudoclass.user.type
to change the value of the input to mismatch the pattern.Relevant code:
Expected behavior
The input element should now have an invalid state.
Actual behavior
The input element still have a valid state
User-event version
14.5.2
Environment
Testing Library framework:
@testing-library/react@14.1.2
Test environment:
vitest@1.1.1
DOM implementation:
jsdom@23.0.1
Additional context
A bit clarification why I think this is likely a
user-event
bugIf I remove the
user.type
line and change the initial value to mismatch the pattern, the style test would pass.If I have an initially matched value, but set it to a mismatching value from container, the test also succeeds:
But
waitFor
won't help:The text was updated successfully, but these errors were encountered: