jest-dom
jest-dom copied to clipboard
Added jest matcher support for .toHaveValue()
What: Added jest matcher support for .toHaveValue().
Why: Addressing issue on #165 and for greater flexibility in tests.
How: Similar to https://github.com/testing-library/jest-dom/pull/93/.
Checklist:
- [x] Documentation
- [x] Tests
- [x] Updated Type Definitions
- [ ] Ready to be merged
@gnapse I'd like to add the same support to toHaveFormValues where you can provide a matcher per property or a matcher for the whole form, however I noticed there's a test that expects an array of values to match regardless of the order and I'm wondering how useful that is: https://github.com/testing-library/jest-dom/blob/master/src/tests/to-have-form-values.js#L132-L140.
I guess this means that this PR would also remove that functionality from toHaveValue, since their implementation is very similar.
As it stands we wouldn't be able to switch out the implementation for this.equals because it's checking the order of arrays under the hood and therefore wouldn't be able to support jest matchers for .toHaveValue and .toHaveFormValue. I'd personally be in favour of using this.equals and enforce array order for matchers and allow us to use jest matchers. What are your thoughts?
@connormeredith sorry that this has slipped off our plate for so long. But it still sounds like an interesting path to follow. Do you have the bandwidth to resume working on this and ship it? If not that's ok. I got the gist of it and I think I can help finishing it too. Let me know and I'll plan accordingly.
Any news on this? I have noticed that I can not use regexes to assert values with the toHaveValue matcher
Oh boy this is embarrassing. @connormeredith I'm ready to merge this. Can you take care of the merge conflict? That file needs to be removed, since types are no longer maintained by us.