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

prop-types-exact prevents user from using data-testid prop for locating components during testing #4788

Closed
vjpr opened this issue Jul 16, 2018 · 3 comments

Comments

@vjpr
Copy link

vjpr commented Jul 16, 2018

Bug report

Describe the bug

When using the common data-testid practice for components (https://blog.kentcdodds.com/making-your-ui-tests-resilient-to-change-d37a6ee37269), prop-types-exact prints errors that are not able to be disabled.

Was added here: #2516

suprraz/babel-plugin-react-element-info#2

Solutions

a. Remove prop-types-exact
b. Add another prop to Link that allows disabling it (escape hatch).

Workaround

Wrap Link component, and don't add data-testid to next/link, only to the wrapper.

@timneutkens
Copy link
Member

Adding data-testid to <Link> won't add anything to the resulting HTML document, adding it to <a> or the element under <Link> will, so the exact proptypes check is correct here, and this is not a bug.

@vjpr
Copy link
Author

vjpr commented Jul 16, 2018

Its more of a unintentional restriction of testability, a feature request I guess.

If you have a Link that you want to test with Selenium/Cypress, you cannot add a data-testid prop to make it easy to find without causing this ugly error.

The use of this prop-types-exact lib makes it impossible.

@vjpr
Copy link
Author

vjpr commented Jul 16, 2018

Ah wait, I see what you mean. I was using a babel-plugin to generate the data tags. Placing one on the Link tag would never make it to the dom anyway as you said.

So the workaround I mentioned above is really the only viable solution, and is user-land.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants