UNPKG

3.6 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { NgZone } from '@angular/core';
9import { MatchMedia } from '../match-media';
10import { BreakPointRegistry } from '../../breakpoints/break-point-registry';
11/**
12 * MockMatchMedia mocks calls to the Window API matchMedia with a build of a simulated
13 * MockMediaQueryListener. Methods are available to simulate an activation of a mediaQuery
14 * range and to clearAll mediaQuery listeners.
15 */
16export declare class MockMatchMedia extends MatchMedia {
17 private _breakpoints;
18 autoRegisterQueries: boolean;
19 useOverlaps: boolean;
20 constructor(_zone: NgZone, _platformId: Object, _document: any, _breakpoints: BreakPointRegistry);
21 /** Easy method to clear all listeners for all mediaQueries */
22 clearAll(): void;
23 /** Feature to support manual, simulated activation of a mediaQuery. */
24 activate(mediaQuery: string, useOverlaps?: boolean): boolean;
25 /** Converts an optional mediaQuery alias to a specific, valid mediaQuery */
26 _validateQuery(queryOrAlias: string): string;
27 /**
28 * Manually onMediaChange any overlapping mediaQueries to simulate
29 * similar functionality in the window.matchMedia()
30 */
31 private _activateWithOverlaps;
32 /**
33 *
34 */
35 private _activateByAlias;
36 /**
37 *
38 */
39 private _activateByQuery;
40 /** Deactivate all current MQLs and reset the buffer */
41 private _deactivateAll;
42 /** Insure the mediaQuery is registered with MatchMedia */
43 private _registerMediaQuery;
44 /**
45 * Call window.matchMedia() to build a MediaQueryList; which
46 * supports 0..n listeners for activation/deactivation
47 */
48 protected buildMQL(query: string): MediaQueryList;
49 protected get hasActivated(): boolean;
50}
51/**
52 * Special internal class to simulate a MediaQueryList and
53 * - supports manual activation to simulate mediaQuery matching
54 * - manages listeners
55 */
56export declare class MockMediaQueryList implements MediaQueryList {
57 private _mediaQuery;
58 private _isActive;
59 private _listeners;
60 get matches(): boolean;
61 get media(): string;
62 constructor(_mediaQuery: string);
63 /**
64 * Destroy the current list by deactivating the
65 * listeners and clearing the internal list
66 */
67 destroy(): void;
68 /** Notify all listeners that 'matches === TRUE' */
69 activate(): MockMediaQueryList;
70 /** Notify all listeners that 'matches === false' */
71 deactivate(): MockMediaQueryList;
72 /** Add a listener to our internal list to activate later */
73 addListener(listener: MediaQueryListListener): void;
74 /** Don't need to remove listeners in the testing environment */
75 removeListener(_: MediaQueryListListener | null): void;
76 addEventListener<K extends keyof MediaQueryListEventMap>(_: K, __: (this: MediaQueryList, ev: MediaQueryListEventMap[K]) => any, ___?: boolean | AddEventListenerOptions): void;
77 removeEventListener<K extends keyof MediaQueryListEventMap>(_: K, __: (this: MediaQueryList, ev: MediaQueryListEventMap[K]) => any, ___?: boolean | EventListenerOptions): void;
78 dispatchEvent(_: Event): boolean;
79 onchange: MediaQueryListListener;
80}
81/**
82 * Pre-configured provider for MockMatchMedia
83 */
84export declare const MockMatchMediaProvider: {
85 provide: typeof MatchMedia;
86 useClass: typeof MockMatchMedia;
87};
88declare type MediaQueryListListener = ((this: MediaQueryList, ev: MediaQueryListEvent) => any) | null;
89export {};
90
\No newline at end of file