Testing recommendations
Our general set of do's and don'ts for testing components and views.
Choose the right selectors
Follow RTL's Guiding Principles and query priorities when choosing the right element selectors.
Prioritize accessible and semantic queries (e.g.,
[role="dialog"]
) followed by data-test-subj
attributes over other, more complicated and prone to breaking queries (e.g. div > span.title
) whenever possible.
Check out our component-specific testing docs to find the selectors we officially support.
tsx code block:screen.getByRole('dialog'); // react-testing-library cy.get('[role="dialog"]'); // cypress driver.findElement(By.cssSelector('[role="dialog"]')); // selenium
Do:ย Use accessible and semantic queries.
tsx code block:container.querySelector('.euiFlyout'); // react-testing-library cy.get('.euiFlyout'); // cypress driver.findElement(By.cssSelector('.euiFlyout')); // selenium
Don't: