Skip to content

Instantly share code, notes, and snippets.

@madflanderz
Last active November 26, 2019 08:58
Show Gist options
  • Save madflanderz/370f1a7ca5240ae6590934f52dcec372 to your computer and use it in GitHub Desktop.
Save madflanderz/370f1a7ca5240ae6590934f52dcec372 to your computer and use it in GitHub Desktop.
react-testing-library order of elements
/**
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