Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sharing matching details between getByRole & queryByRole #1227

Open
flakey-bit opened this issue Apr 17, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@flakey-bit
Copy link

Describe the feature you'd like:

When writing tests we'll often write a positive test i.e. something appears when we expect it to with a corresponding negative test i.e. it doesn't appear when it shouldn't.

For various reasons we want to keep things DRY (e.g. if the text changes, we don't want false-negatives in the negative test).

At the moment, the best we can come up with is

const warningMatcher: [ByRoleMatcher, ByRoleOptions] = [
  (content, element) => content === "status" && element?.textContent?.includes("The file has warning(s) that may affect how your data will import"),
  {}
];

Then

// Positive case i.e. we're looking for the warning
expect(screen.getByRole(...warningMatcher)).toBeInTheDocument();

// Negative case i.e. we're asserting the warning does not appear
expect(screen.queryByRole(...warningMatcher)).not.toBeInTheDocument();

Wondering if API changes could make this (surely common?) use-case easier.

@eps1lon eps1lon added the enhancement New feature or request label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants