Last active
November 26, 2019 08:58
-
-
Save madflanderz/370f1a7ca5240ae6590934f52dcec372 to your computer and use it in GitHub Desktop.
react-testing-library order of elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
To check the order of elements you can use the underlying dom testing lib to search in specific elements. The following example gets all table rows and checks then for specific text in each row. | |
**/ | |
import { getByText as domGetByText } from "@testing-library/react" | |
describe("StockTable", () => { | |
it("renders countries in correct order by country code", async () => { | |
const { getAllByTestId } = render(<StockTable offers={offers} />) | |
const tableRows = getAllByTestId("table-row") | |
domGetByText(tableRows[0], /Denmark/) | |
domGetByText(tableRows[1], /Spain/) | |
domGetByText(tableRows[2], /France/) | |
}) | |
}) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment