[Radio, Checkbox, Time Input]: Document the need to mock window.matchMedia for jest tests
See original GitHub issueIssue Description
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.
Issue Type
- New Feature
- Enhancement
- Bug
- Other
Expected Behavior
Our jest tests should not fail when consuming terra-form-radio/terra-form-checkbox
Steps to Reproduce
- Consume radio/checkbox
- Run jest test on a component that uses radio/checkbox
Environment
- Component Version: terra-form-radio (2.0.0), terra-form-checkbox (2.0.0)
- Browser Name and Version: All
- Operating System and version (desktop or mobile): All
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Manual Mocks - Jest
Jest returns TypeError: window.matchMedia is not a function and doesn't properly execute the test. In this case, mocking matchMedia in the test ......
Read more >How can I mock the JavaScript 'window' object using Jest?
Use the mockImplementation approach (the most Jest-like way), but it will work only for those variables which has some default implementation ...
Read more >Issue with jest test and window.matchMedia #1307 - GitHub
Try to mock window.matchmedia on Jest tests. ... I have the same mock code in vanilla js project and everything work fine for...
Read more >Jest test failing and not receiving toHaveBeenCalled from ...
[Solved]-Jest test failing and not receiving toHaveBeenCalled from simulated click-Reactjs. Search. score:0. const component = mount( <AddItem />);.
Read more >Window matchMedia() Method - W3Schools
The matchMedia() method returns a MediaQueryList with the results from the query. ... To run responsive media query whenever the window state changes, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bjankord, Please review https://github.com/cerner/terra-core/pull/2532
@prachigotkhindikar1 Feel free to send over a PR!