1- import { NO_ERRORS_SCHEMA } from '@angular/core' ;
1+ import { NO_ERRORS_SCHEMA , PLATFORM_ID } from '@angular/core' ;
22import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
33import { ActivatedRoute } from '@angular/router' ;
44
@@ -9,6 +9,7 @@ import { of as observableOf } from 'rxjs';
99import { XSRFService } from '../core/xsrf/xsrf.service' ;
1010import { LoginPageComponent } from './login-page.component' ;
1111import { ActivatedRouteStub } from '../shared/testing/active-router.stub' ;
12+ import { By } from '@angular/platform-browser' ;
1213
1314describe ( 'LoginPageComponent' , ( ) => {
1415 let comp : LoginPageComponent ;
@@ -24,29 +25,65 @@ describe('LoginPageComponent', () => {
2425 select : observableOf ( true )
2526 } ) ;
2627
27- beforeEach ( waitForAsync ( ( ) => {
28- TestBed . configureTestingModule ( {
29- imports : [
30- TranslateModule . forRoot ( )
31- ] ,
32- declarations : [ LoginPageComponent ] ,
33- providers : [
34- { provide : ActivatedRoute , useValue : activatedRouteStub } ,
35- { provide : Store , useValue : store } ,
36- { provide : XSRFService , useValue : { } } ,
37- ] ,
38- schemas : [ NO_ERRORS_SCHEMA ]
39- } ) . compileComponents ( ) ;
40- } ) ) ;
41-
42- beforeEach ( ( ) => {
43- fixture = TestBed . createComponent ( LoginPageComponent ) ;
44- comp = fixture . componentInstance ; // SearchPageComponent test instance
45- fixture . detectChanges ( ) ;
28+ describe ( 'when platform is browser' , ( ) => {
29+ beforeEach ( waitForAsync ( ( ) => {
30+ TestBed . configureTestingModule ( {
31+ imports : [
32+ TranslateModule . forRoot ( )
33+ ] ,
34+ declarations : [ LoginPageComponent ] ,
35+ providers : [
36+ { provide : ActivatedRoute , useValue : activatedRouteStub } ,
37+ { provide : Store , useValue : store } ,
38+ { provide : XSRFService , useValue : { } } ,
39+ { provide : PLATFORM_ID , useValue : 'browser' }
40+ ] ,
41+ schemas : [ NO_ERRORS_SCHEMA ]
42+ } ) . compileComponents ( ) ;
43+ } ) ) ;
44+
45+ beforeEach ( ( ) => {
46+ fixture = TestBed . createComponent ( LoginPageComponent ) ;
47+ comp = fixture . componentInstance ; // SearchPageComponent test instance
48+ fixture . detectChanges ( ) ;
49+ } ) ;
50+
51+ it ( 'should create instance' , ( ) => {
52+ const login = fixture . debugElement . query ( By . css ( '[data-test="login"]' ) ) ;
53+ const loading = fixture . debugElement . query ( By . css ( '[data-test="loading"]' ) ) ;
54+ expect ( login ) . toBeTruthy ( ) ;
55+ expect ( loading ) . toBeFalsy ( ) ;
56+ } ) ;
4657 } ) ;
4758
48- it ( 'should create instance' , ( ) => {
49- expect ( comp ) . toBeDefined ( ) ;
59+ describe ( 'when platform is browser' , ( ) => {
60+ beforeEach ( waitForAsync ( ( ) => {
61+ TestBed . configureTestingModule ( {
62+ imports : [
63+ TranslateModule . forRoot ( )
64+ ] ,
65+ declarations : [ LoginPageComponent ] ,
66+ providers : [
67+ { provide : ActivatedRoute , useValue : activatedRouteStub } ,
68+ { provide : Store , useValue : store } ,
69+ { provide : PLATFORM_ID , useValue : 'server' }
70+ ] ,
71+ schemas : [ NO_ERRORS_SCHEMA ]
72+ } ) . compileComponents ( ) ;
73+ } ) ) ;
74+
75+ beforeEach ( ( ) => {
76+ fixture = TestBed . createComponent ( LoginPageComponent ) ;
77+ comp = fixture . componentInstance ; // SearchPageComponent test instance
78+ fixture . detectChanges ( ) ;
79+ } ) ;
80+
81+ it ( 'should create instance' , ( ) => {
82+ const login = fixture . debugElement . query ( By . css ( '[data-test="login"]' ) ) ;
83+ const loading = fixture . debugElement . query ( By . css ( '[data-test="loading"]' ) ) ;
84+ expect ( login ) . toBeFalsy ( ) ;
85+ expect ( loading ) . toBeTruthy ( ) ;
86+ } ) ;
5087 } ) ;
5188
5289} ) ;
0 commit comments