From 14d478cb6672b501c257a716b7093f342c566a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Fri, 26 Apr 2024 12:58:49 +0200 Subject: [PATCH] Provide a mock implementation for window.matchMedia 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. --- src/web/setupTests.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/web/setupTests.js b/src/web/setupTests.js index d4967e727c..2097175f86 100644 --- a/src/web/setupTests.js +++ b/src/web/setupTests.js @@ -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(), + }; +});