After consuming terra-form-radio and terra-form-checkbox, our jest tests started to fail with this error:
TypeError: window.matchMedia is not a function
at Object.isConsideredMobileDevice (node_modules/terra-form-radio/lib/_RadioUtil.js:8:17)
at Radio (node_modules/terra-form-radio/lib/Radio.js:140:131)
The file is here: _RadioUtil.js.
The same issue exists with CheckboxUtil as well.
Our jest tests should not fail when consuming terra-form-radio/terra-form-checkbox
After a slight bit of investigation and discussion with @yuderekyu, we have found that there is a way to get around the issue by mocking out window.matchMedia like so:
window.matchMedia = () => ({ matches: true });
like you have in your jestsetup.js file.
Is this something that we, as a consumer, should be doing on our end?
Yes, we'd recommend updating your jestsetup.js file to mock window.matchMedia with the code @yuderekyu provided.
Is it possible to add that recommendation to the documentation of those components? It would surely be helpful for other consumers to know that you _must_ mock window.matchMedia for jest tests not to fail.
@PseudoFaux Would you be up for sending a PR to update the doc?
@PseudoFaux / @bjankord, checking to see if a PR has already been made to update the doc. If not, I would be happy to make one. Thanks!
@prachigotkhindikar1 Feel free to send over a PR!
@bjankord, Please review https://github.com/cerner/terra-core/pull/2532
Looks good, just need to update the changelog files.