Skip to content

Commit 8c26eff

Browse files
authored
Added matchMedia mock function for Testing purposes (#3130)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 044c265 commit 8c26eff

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

portal-ui/src/common/SecureComponent/__tests__/accessControl.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
import "../../../utils/matchMedia";
1718
import hasPermission from "../accessControl";
1819
import { store } from "../../../store";
1920
import { IAM_PAGES, IAM_PAGES_PERMISSIONS, IAM_SCOPES } from "../permissions";

portal-ui/src/utils/matchMedia.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Object.defineProperty(window, "matchMedia", {
2+
writable: true,
3+
value: jest.fn().mockImplementation((query) => ({
4+
matches: false,
5+
media: query,
6+
onchange: null,
7+
addListener: jest.fn(), // Deprecated
8+
removeListener: jest.fn(), // Deprecated
9+
addEventListener: jest.fn(),
10+
removeEventListener: jest.fn(),
11+
dispatchEvent: jest.fn(),
12+
})),
13+
});

0 commit comments

Comments
 (0)