Skip to content

Commit

Permalink
Provide a mock implementation for window.matchMedia
Browse files Browse the repository at this point in the history
It seems window.matchMedia is required for the Select components now.
Thus implement a mock of the API for being able to test the select
components.
  • Loading branch information
bjoernricks committed Apr 29, 2024
1 parent 0b4eccf commit 14d478c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/web/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ HTMLAnchorElement.prototype.click = testing.fn();
window.URL.createObjectURL = testing.fn();

global.ResizeObserver = ResizeObserverModule.default;

// avoid TypeError: window.matchMedia is not a function for @mantine/core/Select
window.matchMedia = testing.fn().mockImplementation(query => {
return {
matches: false,
media: query,
onchange: null,
addListener: testing.fn(), // deprecated
removeListener: testing.fn(), // deprecated
addEventListener: testing.fn(),
removeEventListener: testing.fn(),
dispatchEvent: testing.fn(),
};
});

0 comments on commit 14d478c

Please sign in to comment.