@@ -34,7 +34,7 @@ describe('BreakpointObserver', () => {
34
34
} ) ;
35
35
36
36
it ( 'retrieves the whether a query is currently matched' , ( ) => {
37
- let query = 'everything starts as true in the FakeMediaMatcher' ;
37
+ const query = 'everything starts as true in the FakeMediaMatcher' ;
38
38
expect ( breakpointManager . isMatched ( query ) ) . toBeTruthy ( ) ;
39
39
} ) ;
40
40
@@ -61,15 +61,15 @@ describe('BreakpointObserver', () => {
61
61
} ) ;
62
62
63
63
it ( 'accepts an array of queries' , ( ) => {
64
- let queries = [ '1 query' , '2 query' , 'red query' , 'blue query' ] ;
64
+ const queries = [ '1 query' , '2 query' , 'red query' , 'blue query' ] ;
65
65
breakpointManager . observe ( queries ) ;
66
66
expect ( mediaMatcher . queryCount ) . toBe ( queries . length ) ;
67
67
} ) ;
68
68
69
69
it ( 'completes all events when the breakpoint manager is destroyed' , ( ) => {
70
- let firstTest = jasmine . createSpy ( 'test1' ) ;
70
+ const firstTest = jasmine . createSpy ( 'test1' ) ;
71
71
breakpointManager . observe ( 'test1' ) . subscribe ( undefined , undefined , firstTest ) ;
72
- let secondTest = jasmine . createSpy ( 'test2' ) ;
72
+ const secondTest = jasmine . createSpy ( 'test2' ) ;
73
73
breakpointManager . observe ( 'test2' ) . subscribe ( undefined , undefined , secondTest ) ;
74
74
75
75
expect ( firstTest ) . not . toHaveBeenCalled ( ) ;
@@ -82,8 +82,8 @@ describe('BreakpointObserver', () => {
82
82
} ) ;
83
83
84
84
it ( 'emits an event on the observable when values change' , ( ) => {
85
- let query = '(width: 999px)' ;
86
- let queryMatchState : boolean = false ;
85
+ const query = '(width: 999px)' ;
86
+ let queryMatchState = false ;
87
87
breakpointManager . observe ( query ) . subscribe ( ( state : BreakpointState ) => {
88
88
queryMatchState = state . matches ;
89
89
} ) ;
@@ -93,14 +93,31 @@ describe('BreakpointObserver', () => {
93
93
expect ( queryMatchState ) . toBeFalsy ( ) ;
94
94
} ) ;
95
95
96
+ it ( 'emits an event on the observable with the matching state of all queries provided' , ( ) => {
97
+ const queryOne = '(width: 999px)' ;
98
+ const queryTwo = '(width: 700px)' ;
99
+ let state : BreakpointState = { matches : false , breakpoints : { } } ;
100
+ breakpointManager . observe ( [ queryOne , queryTwo ] ) . subscribe ( ( breakpoint : BreakpointState ) => {
101
+ state = breakpoint ;
102
+ } ) ;
103
+
104
+ mediaMatcher . setMatchesQuery ( queryOne , false ) ;
105
+ mediaMatcher . setMatchesQuery ( queryTwo , false ) ;
106
+ expect ( state . breakpoints ) . toEqual ( { [ queryOne ] : false , [ queryTwo ] : false } ) ;
107
+
108
+ mediaMatcher . setMatchesQuery ( queryOne , true ) ;
109
+ mediaMatcher . setMatchesQuery ( queryTwo , false ) ;
110
+ expect ( state . breakpoints ) . toEqual ( { [ queryOne ] : true , [ queryTwo ] : false } ) ;
111
+ } ) ;
112
+
96
113
it ( 'emits a true matches state when the query is matched' , ( ) => {
97
- let query = '(width: 999px)' ;
114
+ const query = '(width: 999px)' ;
98
115
mediaMatcher . setMatchesQuery ( query , true ) ;
99
116
expect ( breakpointManager . isMatched ( query ) ) . toBeTruthy ( ) ;
100
117
} ) ;
101
118
102
119
it ( 'emits a false matches state when the query is not matched' , ( ) => {
103
- let query = '(width: 999px)' ;
120
+ const query = '(width: 999px)' ;
104
121
mediaMatcher . setMatchesQuery ( query , false ) ;
105
122
expect ( breakpointManager . isMatched ( query ) ) . toBeTruthy ( ) ;
106
123
} ) ;
@@ -130,7 +147,7 @@ export class FakeMediaQueryList implements MediaQueryList {
130
147
@Injectable ( )
131
148
export class FakeMediaMatcher {
132
149
/** A map of match media queries. */
133
- private queries : Map < string , FakeMediaQueryList > = new Map ( ) ;
150
+ private queries = new Map < string , FakeMediaQueryList > ( ) ;
134
151
135
152
/** The number of distinct queries created in the media matcher during a test. */
136
153
get queryCount ( ) : number {
@@ -139,7 +156,7 @@ export class FakeMediaMatcher {
139
156
140
157
/** Fakes the match media response to be controlled in tests. */
141
158
matchMedia ( query : string ) : FakeMediaQueryList {
142
- let mql = new FakeMediaQueryList ( true , query ) ;
159
+ const mql = new FakeMediaQueryList ( true , query ) ;
143
160
this . queries . set ( query , mql ) ;
144
161
return mql ;
145
162
}
0 commit comments