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

testing-library/prefer-screen-queries with self-written helpers #340

Closed
pustovalov opened this issue Apr 14, 2021 · 6 comments · Fixed by #342
Closed

testing-library/prefer-screen-queries with self-written helpers #340

pustovalov opened this issue Apr 14, 2021 · 6 comments · Fixed by #342
Assignees
Labels
bug Something isn't working released

Comments

@pustovalov
Copy link

Hey

expect(await findByComplexText(screen, 'Selected campaigns 0')).toBeInTheDocument()

eslint-plugin-testing-library@3.10.2 - no errors

eslint-plugin-testing-library@4.0.1 - Avoid destructuring queries from render result, use screen.findByComplexText instead testing-library/prefer-screen-queries

should this rule only apply to testing-library methods?

@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

Hello @pustovalov. Did you check the migration guide to v4? That error is reported by prefer-screen-queries which has been enabled in all Shareable Configs and mentioned as one of the things to be aware of when migrating.

You are still able to switch the rule off if you are not interested in it tough.

@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

My bad, I think I misunderstood the actual issue.

You are getting a non-related Testing Library method reported as a Testing Library query right? Can you confirm if your findByComplexText is a custom query? If so, I think we need to improve the checks in this rule to avoid reporting custom ones since they are not attached to screen (I'm not sure if this is possible actually).

If it's not a custom query but something completely unrelated to Testing Library, Aggressive Reporting is causing that but there is no option to switch it off for queries yet. It should be available in the following days.

@pustovalov
Copy link
Author

That error is reported by prefer-screen-queries which has been enabled in all Shareable Configs and mentioned as one of the things to be aware of when migrating.

I have used this rule before and there were no errors

this is not custom query, it's just a function which uses screen, this is a findByComplexText:

export function findByComplexText(screen, text) {
  return screen.findByText((content, node) => {
    const hasText = node => node.textContent === text
    const nodeHasText = hasText(node)
    const childrenDontHaveText = Array.from(node.children).every(child => !hasText(child))

    return nodeHasText && childrenDontHaveText
  })
}

@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

Thanks for sharing! That function is understood by the plugin as a custom query, which is fine! So you can get the advantage of other rules linting that function, like await-async-query complaining about not awaiting your findByComplexText for example.

However, it doesn't make sense to get prefer-screen-queries reporting custom queries since you are not able to access them through screen. This is a bug indeed, but should be easy to solve! Thanks for reporting and sorry about the misunderstood in my first message.

We'll get back when it's fixed 🚀

@Belco90 Belco90 added the bug Something isn't working label Apr 14, 2021
@Belco90 Belco90 self-assigned this Apr 15, 2021
Belco90 added a commit that referenced this issue Apr 16, 2021
* fix(prefer-screen-queries): avoid reporting custom queries

* docs(prefer-screen-queries): update examples, exceptions and reading

Closes #340
@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@pustovalov
Copy link
Author

@Belco90 Thx, new version works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
2 participants