55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- import { Component , Directive , OnInit } from '@angular/core' ;
9- import { CommonModule } from '@angular/common' ;
8+ import { Component , Directive , OnInit , PLATFORM_ID } from '@angular/core' ;
9+ import { CommonModule , isPlatformBrowser } from '@angular/common' ;
1010import { ComponentFixture , TestBed , inject } from '@angular/core/testing' ;
1111import {
1212 ɵMatchMedia as MatchMedia ,
@@ -35,15 +35,17 @@ describe('show directive', () => {
3535 let fixture : ComponentFixture < any > ;
3636 let mediaController : MockMatchMedia ;
3737 let styler : StyleUtils ;
38+ let platformId : Object ;
3839 let createTestComponent = ( template : string ) => {
3940 fixture = makeCreateTestComponent ( ( ) => TestShowComponent ) ( template ) ;
4041
4142 // Can only Inject() AFTER TestBed.override(...)
4243 inject (
43- [ MatchMedia , StyleUtils ] ,
44- ( _matchMedia : MockMatchMedia , _styler : StyleUtils ) => {
44+ [ MatchMedia , StyleUtils , PLATFORM_ID ] ,
45+ ( _matchMedia : MockMatchMedia , _styler : StyleUtils , _platformId : Object ) => {
4546 mediaController = _matchMedia ;
4647 styler = _styler ;
48+ platformId = _platformId ;
4749 } ) ( ) ;
4850
4951 return fixture ;
@@ -292,9 +294,15 @@ describe('show directive', () => {
292294 fixture . detectChanges ( ) ;
293295
294296 // NOTE: platform-server can't compute display for unknown elements
295- expectEl ( queryFor ( fixture , elSelector ) [ 0 ] ) . toHaveCSS ( {
296- 'display' : 'initial'
297- } , styler ) ;
297+ if ( isPlatformBrowser ( platformId ) ) {
298+ expectEl ( queryFor ( fixture , elSelector ) [ 0 ] ) . toHaveCSS ( {
299+ 'display' : 'inline'
300+ } , styler ) ;
301+ } else {
302+ expectEl ( queryFor ( fixture , elSelector ) [ 0 ] ) . not . toHaveStyle ( {
303+ 'display' : '*'
304+ } , styler ) ;
305+ }
298306
299307 mediaController . activate ( 'xs' ) ;
300308 fixture . detectChanges ( ) ;
@@ -305,9 +313,15 @@ describe('show directive', () => {
305313 mediaController . activate ( 'lg' ) ;
306314 fixture . detectChanges ( ) ;
307315 // NOTE: platform-server can't compute display for unknown elements
308- expectEl ( queryFor ( fixture , elSelector ) [ 0 ] ) . toHaveCSS ( {
309- 'display' : 'initial'
310- } , styler ) ;
316+ if ( isPlatformBrowser ( platformId ) ) {
317+ expectEl ( queryFor ( fixture , elSelector ) [ 0 ] ) . toHaveCSS ( {
318+ 'display' : 'inline'
319+ } , styler ) ;
320+ } else {
321+ expectEl ( queryFor ( fixture , elSelector ) [ 0 ] ) . not . toHaveStyle ( {
322+ 'display' : '*'
323+ } , styler ) ;
324+ }
311325 } ) ;
312326 } ) ;
313327
0 commit comments