Skip to content

Instantly share code, notes, and snippets.

@sibelius
Last active September 5, 2023 13:30
Show Gist options
  • Save sibelius/bf49eeb2eada00d63b533866cc510556 to your computer and use it in GitHub Desktop.
Save sibelius/bf49eeb2eada00d63b533866cc510556 to your computer and use it in GitHub Desktop.
get all data-testid from your DOM, useful when working in testing-library tests
// thanks to http://twitter.com/@KrComet
export const getAvailableTestIds = () => {
// eslint-disable-next-line
console.log(new Set([...document.querySelectorAll('[data-testid]')].map((el) => el.dataset.testid)));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment