Skip to content

Commit

Permalink
fix(mock-doc): adjust matchMedia mock return
Browse files Browse the repository at this point in the history
  • Loading branch information
bdriguesdev committed Jun 26, 2023
1 parent 94eb855 commit eda92f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/mock-doc/test/match-media.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
8 changes: 5 additions & 3 deletions src/mock-doc/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down

0 comments on commit eda92f5

Please sign in to comment.