CodePark/ questions / Forms & accessibility
START PRACTICINGPRACTICE
Frontend question · Testing › Forms & accessibility

After await user.type(input, 'ana@x.com'), which assertion correctly checks what the input contains?

expect(input).toHaveValue('ana@x.com')

toHaveValue is right, because it reads the current value of the form control. The tempting toHaveAttribute('value', ...) option is wrong. The value attribute holds the initial value, not what the user typed. toHaveTextContent is wrong because inputs have no text content. toBeInTheDocument expects an element, not a string.