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(), + })), +})