Skip to content

Commit

Permalink
Fixes for test failures caused by undefined window.matchMedia
Browse files Browse the repository at this point in the history
  • Loading branch information
jcohen02 committed May 13, 2020
1 parent 60eb795 commit f031c55
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/js/__tests__/addFile.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./windowMatchMedia.mock";
import { create } from '../index.js';

describe('adding files', () => {
Expand Down
1 change: 1 addition & 0 deletions src/js/__tests__/callbacks.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./windowMatchMedia.mock";
import { create, OptionTypes, FileStatus } from '../index.js';

describe('adding files', () => {
Expand Down
1 change: 1 addition & 0 deletions src/js/__tests__/createInstance.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./windowMatchMedia.mock";
import { create } from '../index.js';

describe('create instance', () => {
Expand Down
1 change: 1 addition & 0 deletions src/js/__tests__/removeFile.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./windowMatchMedia.mock";
import { create } from '../index.js';

const server = {
Expand Down
1 change: 1 addition & 0 deletions src/js/__tests__/server.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./windowMatchMedia.mock";
import { create } from '../index.js';

describe('setting server property', () => {
Expand Down
1 change: 1 addition & 0 deletions src/js/__tests__/setFiles.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./windowMatchMedia.mock";
import { create } from '../index.js';

const next = (cb) => {
Expand Down
17 changes: 17 additions & 0 deletions src/js/__tests__/windowMatchMedia.mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Mocking window.matchMedia as described in the jest docks
// since this is not defined in JSDOM and causes the tests
// to fail. See: "https://jestjs.io/docs/en/manual-
// mocks#mocking-methods-which-are-not-implemented-in-jsdom"
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: 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(),
})),
});

0 comments on commit f031c55

Please sign in to comment.