Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
fix(tests): fix matchMediaMock issue when running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Nov 28, 2019
1 parent 500c680 commit 2edfe1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/__mocks__/matchMediaMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
window.matchMedia = jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}))
3 changes: 2 additions & 1 deletion src/App.test.tsx → src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../__mocks__/matchMediaMock'
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import App from '../App'

it('renders without crashing', () => {
const div = document.createElement('div')
Expand Down

0 comments on commit 2edfe1b

Please sign in to comment.