-
Notifications
You must be signed in to change notification settings - Fork 148
[prefer-find-by] When query methods come from destructuring, findBy* might not be defined #167
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
Comments
I guess we could look up where it was destructured from and change the properties that are destructured rather than just the named of the called functions? |
From ESLint rules fixes best practices, 1 is a bug here, but 2 and 3 aren't.
👆 Because of this, 1 is a bug as it can cause the code to stop working as
👆 Because of this, 2 and 3 are not an issue. A rule should not take care of possible errors reported by other rules. And they are not causing the code to stop working. |
I thought so. Ok so this ticket should be used to track the fixing of 1. Thanks!! |
How are you planning to fix it? I have couple of ideas, but it can get complex for some edge cases like: const setUp = () => render(<Foo />);
const { getByText } = setUp();
await waitFor(() => getByText('submit')); We can't just destructure from |
the best scenario seems to look up the place where the original query was restructured from, and replace it there if it wasn't already. We will have to set up a good amount of tests to verify all scenarios work as expected |
Cool, we are in the same page then. Indeed, we need a nice bunch of tests here. Apart from that case mentioned before, I can think about these additional ones in case it helps: // keeping render returned queries in `view` variable
const view = render(<Foo />);
await waitFor(() => view.getByText('submit')); // same as previous one but from setup method wrapping render
const setUp = () => render(<Foo />);
const view = setUp();
await waitFor(() => view.getByText('submit')); // findByText already destructured so it shouldn't be added here
const { getByText, findByText } = render(<Foo />);
await waitFor(() => getByText('submit')); // same as previous one but from setup method wrapping render
const setUp = () => render(<Foo />);
const { getByText, findByText } = setUp();
await waitFor(() => getByText('submit')); |
just to clarify, the rule does not cover await waitFor(() => getByText('submit')) |
My bad, I'll update the examples. |
these two should work, as the replaced code will use
yes, we should cover these |
I'm taking this one |
🎉 This issue has been resolved in version 3.3.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Example code before running the linter
After automatically fixing this, the code looks like this
There are a couple of issues:
findByText
is not defined. If the code was usingscreen
or any similar wrapper, instead of the bound function directly, this is not a problem.getByText
is not used elsewhere, it becomes unused, causing another error in the linter that wasn't there before - we've introduced this errorwaitFor
- it might now be unused as wellWe should definitely fix 1. as it otherwise it's a broken code. I guess I could track where
getByText
was defined, and add thefindBy*
function there.Thoughts on 2. and 3 ?
The text was updated successfully, but these errors were encountered: