11import { TestBed } from '@angular/core/testing' ;
22import * as assert from 'assert' ;
33import { catchError , map , mergeMap } from 'rxjs/operators' ;
4-
4+ import { IndividualConfig , ToastrService } from 'ngx-toastr' ;
55import { StatusNetworkService } from './status-network.service' ;
66
77export interface ErrorType {
@@ -11,14 +11,31 @@ export interface ErrorType {
1111}
1212describe ( 'StatusNetworkService' , ( ) => {
1313 let service : StatusNetworkService ;
14- const errorType : ErrorType = { error : catchError , message : 'javascript' , isError : false } ;
14+ const toastrServiceStub = {
15+ error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
16+ warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
17+ } ;
1518
1619 beforeEach ( ( ) => {
17- TestBed . configureTestingModule ( { } ) ;
20+ TestBed . configureTestingModule ( {
21+ providers : [ ToastrService , {
22+ provide : ToastrService , useValue : toastrServiceStub
23+ } ]
24+ } ) ;
1825 service = TestBed . inject ( StatusNetworkService ) ;
1926 } ) ;
2027
28+ fit ( 'checkTypeError is error' , ( ) => {
29+ const errorType : ErrorType = { error : catchError , message : 'javascript' , isError : true } ;
30+ spyOn ( toastrServiceStub , 'error' ) ;
31+ service . checkTypeError ( errorType )
32+ expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
33+ } ) ;
34+
2135 fit ( 'checkTypeError is warning' , ( ) => {
22- assert ( service . checkTypeError ( errorType ) == 'is warning' ) ;
36+ const errorType : ErrorType = { error : catchError , message : 'javascript' , isError : false } ;
37+ spyOn ( toastrServiceStub , 'warning' ) ;
38+ service . checkTypeError ( errorType )
39+ expect ( toastrServiceStub . warning ) . toHaveBeenCalled ( ) ;
2340 } ) ;
2441} ) ;
0 commit comments