From 3b02efa8299fe856f3f439f6d6ce9fc6141e8e52 Mon Sep 17 00:00:00 2001 From: alimpens Date: Tue, 10 Dec 2024 10:24:34 +0100 Subject: [PATCH] Fix test --- packages/react/src/Header/Header.test.tsx | 1 + packages/react/src/Header/matchMedia.mock.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 packages/react/src/Header/matchMedia.mock.ts diff --git a/packages/react/src/Header/Header.test.tsx b/packages/react/src/Header/Header.test.tsx index ddeaa64bec..5a9bfeab02 100644 --- a/packages/react/src/Header/Header.test.tsx +++ b/packages/react/src/Header/Header.test.tsx @@ -1,5 +1,6 @@ import { render, screen } from '@testing-library/react' // import { createRef } from 'react' +import './matchMedia.mock' import { Header } from './Header' import '@testing-library/jest-dom' diff --git a/packages/react/src/Header/matchMedia.mock.ts b/packages/react/src/Header/matchMedia.mock.ts new file mode 100644 index 0000000000..19da954af9 --- /dev/null +++ b/packages/react/src/Header/matchMedia.mock.ts @@ -0,0 +1,15 @@ +// Sourced from https://jestjs.io/docs/29.4/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(), + })), +})