question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Radio, Checkbox, Time Input]: Document the need to mock window.matchMedia for jest tests

See original GitHub issue

Issue 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

  1. Consume radio/checkbox
  2. 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:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bjankordcommented, Jul 16, 2019

@prachigotkhindikar1 Feel free to send over a PR!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found