I've built a simple react application with a searchbar component. The searchbar component contains an Input. For testing Im using Jest with React Testing Library. I want to write a test which tests that the input's placeholder disappears when something is typed into the value of that input.
Searchbar.test.tsx
test("SearchBar placeholder gets replaced by search string", () => {
const handleSearchRequest = jest.fn();
render(<SearchBar searchInputValue="Hello World"/>);
const searchInput = screen.getByPlaceholderText("Search");
expect(searchInput).toBeFalsy(); //test fails
// expect(searchInput).not.toBeInTheDocument(); //test fails
// expect(searchInput).toBeNull(); //test fails
});
Searchbar.tsx
<Input
placeholder="Search"
value={currentValue}
/>
Any ideas of how I should write this test?
searchInput
istruthy
which means that screen.getByPlateholderText is finding the component even though the placeholder is not displayed. – Parmenter