-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Applying suggestion for table cell element query yields no results #334
Comments
Hi @ulisses-alves how are you? :) Actually this doesn't work because it's using a regex to find the value.. screen.getByRole('cell', {
name: 'foo'
}); OR screen.getAllByRole('cell', {
name: /foo/i
}); If you update you HTML |
We could fix that I guess? We currently use regex matches, and the problem is that the regex results in more than one match. We could update the regex in those cases, and see if it would match a single element if it'd include the start and end modifiers, like Alternatively, we could fallback to string matchers, or even default to those. This is a good argument to use string matchers instead of regex. What do you think? |
@smeijer I think it would be interesting, although the way it works with regex is nice, maybe if we could add a clearer message that more than one match was found, the developer wouldn't be confused. |
Well, I developed a test like this: import { render, screen } from "@testing-library/react";
import user from "@testing-library/user-event";
import App from "./App";
test("can receive a new user and show it on a list", () => {
render(<App />);
const nameInput = screen.getByRole("textbox", { name: /name/i });
const emailInput = screen.getByRole("textbox", { name: /email/i });
const button = screen.getByRole("button");
user.click(nameInput);
user.keyboard("jane");
user.click(emailInput);
user.keyboard("[email protected]");
user.click(button);
const name = screen.getByRole("cell", { name: "jane" });
const email = screen.getByRole("cell", { name: "[email protected]" });
expect(name).toBeInTheDocument();
expect(email).toBeInTheDocument();
}); And this test does not pass., but instead gives me an error saying: Nevermind, this solved it for me: import { render, screen, waitFor } from "@testing-library/react";
import user from "@testing-library/user-event";
import App from "./App";
test("can receive a new user and show it on a list", async () => {
render(<App />);
const nameInput = screen.getByRole("textbox", { name: /name/i });
const emailInput = screen.getByRole("textbox", { name: /email/i });
const button = screen.getByRole("button");
await user.click(nameInput);
await user.keyboard("jane");
await user.click(emailInput);
await user.keyboard("[email protected]");
await user.click(button);
const name = screen.getByRole("cell", { name: "jane" });
const email = screen.getByRole("cell", { name: "[email protected]" });
expect(name).toBeInTheDocument();
expect(email).toBeInTheDocument();
}); |
@ldco2016 could you show us your App component? |
Bug Report 🐛
Hi there
I have a simple table structure where I wanted to select its first cell. While applying a better selector suggested by the application, it no longer selects the element.
To Reproduce ✔️
Expected behavior 🤔
The element
<td>foo</td>
should be selectedYour Environment 💻
The text was updated successfully, but these errors were encountered: