ByDisplayValue

Use the ByDisplayValue function to get <input>, <select> or <textarea> elements based on their current displayed value.

Lesson covers:

findAllByDisplayValue(), findByDisplayValue(), getAllByDisplayValue(), getByDisplayValue(), queryAllByDisplayValue(), queryByDisplayValue()

const Component = () => {
  return (
    <div>
      <input defaultValue="Hello there" />
    </div>
  );
};

test('getting the input by current value', () => {
  render(<Component />);

  expect(
    screen.getByDisplayValue(
      'Hello there'
    )
  ).toBeInTheDocument();
});

In this lesson we will go over the various ways to use this.

Loading full lesson content & code...

Ready to try running tests for this lesson?