I can't figure out why userEvent.type is not actually typing. I've used async/await. I even tried to use ".then()" but it just skips that code block. The actual application works fine. I can type into the field and state is updated.
I'm trying to test a MaterialUI TextField:
<TextField
data-testid="productName-field"
label="Product Name"
style={styles.textField}
required
id="productName"
onChange={n => setName(n.target.value)}
value={name}
/>
My test is here:
it("Should allow typing in the name field", async () => {
nameField = screen.getByTestId("productName-field");
const yourName = "your name here";
await userEvent.type(nameField,yourName);
expect(nameField.value).toBe(yourName);
});
from the console:
expect(received).toBe(expected) // Object.is equality
Expected: "your name here"
Received: undefined
54 | const yourName = "your name here";
55 | await userEvent.type(nameField,yourName);
> 56 | expect(nameField.value).toBe(yourName);
| ^
57 | });
I've got a similar TextField in two other components and the same tests in different files and they are all passing.