From eda92f5f9d4e507d7dbc48032736a78c40a8cc97 Mon Sep 17 00:00:00 2001 From: Bruno Bufolin Date: Sun, 25 Jun 2023 21:37:29 -0300 Subject: [PATCH] fix(mock-doc): adjust matchMedia mock return --- src/mock-doc/test/match-media.spec.ts | 12 +++++++++--- src/mock-doc/window.ts | 8 +++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mock-doc/test/match-media.spec.ts b/src/mock-doc/test/match-media.spec.ts index 403db93e218e..b6430ab690ca 100644 --- a/src/mock-doc/test/match-media.spec.ts +++ b/src/mock-doc/test/match-media.spec.ts @@ -19,15 +19,21 @@ describe('matchMedia', () => { it('MediaQueryList.matches', () => { expect(media.matches).toBe(false); }); + it('MediaQueryList.addListener', () => { + expect(media.addListener).toBeDefined(); + }); + it('MediaQueryList.removeListener', () => { + expect(media.removeListener).toBeDefined(); + }); it('MediaQueryList.addEventListener', () => { expect(media.addEventListener).toBeDefined(); }); - it('MediaQueryList.dispatchEvent', () => { - expect(media.dispatchEvent).toBeDefined(); - }); it('MediaQueryList.removeEventListener', () => { expect(media.removeEventListener).toBeDefined(); }); + it('MediaQueryList.dispatchEvent', () => { + expect(media.dispatchEvent).toBeDefined(); + }); it('MediaQueryList.onchange', () => { expect(media.onchange).toBe(null); }); diff --git a/src/mock-doc/window.ts b/src/mock-doc/window.ts index df43fbc8b3cf..12aa5fdc066f 100644 --- a/src/mock-doc/window.ts +++ b/src/mock-doc/window.ts @@ -341,9 +341,11 @@ export class MockWindow { return { media, matches: false, - addEventListener, - dispatchEvent, - removeEventListener, + addListener: (_handler: (ev?: any) => void) => {}, + removeListener: (_handler: (ev?: any) => void) => {}, + addEventListener: (_type: string, _handler: (ev?: any) => void) => {}, + removeEventListener: (_type: string, _handler: (ev?: any) => void) => {}, + dispatchEvent: (_ev: any) => {}, onchange: null as ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | null, }; }