From 2edfe1b247ec5d0e5d5e372e0facb82be535af3f Mon Sep 17 00:00:00 2001 From: Jack Meyer Date: Thu, 28 Nov 2019 11:03:06 -0600 Subject: [PATCH] fix(tests): fix matchMediaMock issue when running tests --- src/__mocks__/matchMediaMock.js | 10 ++++++++++ src/{ => __tests__}/App.test.tsx | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/__mocks__/matchMediaMock.js rename src/{ => __tests__}/App.test.tsx (77%) diff --git a/src/__mocks__/matchMediaMock.js b/src/__mocks__/matchMediaMock.js new file mode 100644 index 0000000000..e5fada4652 --- /dev/null +++ b/src/__mocks__/matchMediaMock.js @@ -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(), +})) diff --git a/src/App.test.tsx b/src/__tests__/App.test.tsx similarity index 77% rename from src/App.test.tsx rename to src/__tests__/App.test.tsx index 4bf19359ea..692a59c330 100644 --- a/src/App.test.tsx +++ b/src/__tests__/App.test.tsx @@ -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')