import { ComponentFixture , TestBed , async } from '@angular/core/testing' ; import { Router } from '@angular/router' ; import { RouterTestingModule } from '@angular/router/testing' ; import { UserComponent } from './user.component' ; describe ( 'UserComponent' , ( ) => { let component ; let fixture ; let router ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { imports : [ RouterTestingModule ] , declarations : [ UserComponent ] } ) . compileComponents ( ) ; router = TestBed . inject ( Router ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( UserComponent ) ; component = fixture . componentInstance ; fixture . detectChanges ( ) ; } ) ; it ( 'should create' , ( ) => { expect ( component ) . toBeTruthy ( ) ; } ) ; it ( 'should create' , ( ) => { fixture . ngZone . run ( ( ) => { component . onClick ( ) ; fixture . detectChanges ( ) ; fixture . whenStable ( ) . then ( ( ) => { expect ( router . url ) . toBe ( '/users' ) ; } ) ; } ) ; } ) ; } ) ;