-
Notifications
You must be signed in to change notification settings - Fork 273
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
toHaveTextContent matching rules are not aligned with jest-dom #1613
Comments
@AugustinLF good to see you back mate! 🙌 Regarding the change I have couple of thoughts: As for your use case, if you use exactly the same code to run RTL and RNTL tests, then consider creating own Jest matcher, that would conditionally call JestDOM or RNTL matchers with proper options. That seems like a more bulletproof solution. Alternatively you can pass regex instead of string, and in such case both implementations should work the same. Wdyt? |
You're raising good points. I don't think the fact that such a change would require a major bump is a blocker (we can definitely wait to do such a change when planning to release the next major version), but as highlighted in your answer, the question is indeed "do we think this API change would be beneficial". Personally I think that the API exposed by RNTL is the better one (aligning with But then I'll raise that on the In the meanwhile, would you be up for a PR that allows exporting the matchers, so I can (similarly to import matchers from '@testing-library/react-native/matchers'
const { toHaveTextContent, ...rest } = matchers
expect.extend({
...rest,
toHaveTextContent: myCustomMatcher,
}) That way I could go indeed go over each matchers, and add what makes sense for both platforms? |
@AugustinLF sorry for late reply. Yes, you can submit a PR with export for matchers in RNTL. |
Hey hey, long time not posted here^^'
Describe the bug
toHaveTextContent()
does exact matching by default, while the same helper exposed by jest-dom does partial matching.Expected behavior
I would expect both APIs to behave similarly. Furthermore, the
jest-dom
matcher doesn't support theexact
option, which makes it a bit hard to run both web and native tests with the same code.I'll happily open a conversion in jest-dom's repo, but we should be sure of what we want before hand. Have you had discussions with them on this topic?
The text was updated successfully, but these errors were encountered: