Getbydisplayvalue React Testing Library May 2026

const nameInput = screen.getByLabelText(/name/i);

// Assert updated display value expect(screen.getByDisplayValue('Bob')).toBeInTheDocument(); ); getbydisplayvalue react testing library

// Edit the value await userEvent.clear(nameInput); await userEvent.type(nameInput, 'Bob'); const nameInput = screen

test('select element by display value', () => render(<RoleSelect defaultValue="Admin" />); const nameInput = screen.getByLabelText(/name/i)

// Assert initial display value expect(screen.getByDisplayValue('Alice')).toBeInTheDocument();