1
1
import { TestBed } from '@angular/core/testing' ;
2
2
import * as assert from 'assert' ;
3
3
import { catchError , map , mergeMap } from 'rxjs/operators' ;
4
-
4
+ import { IndividualConfig , ToastrService } from 'ngx-toastr' ;
5
5
import { StatusNetworkService } from './status-network.service' ;
6
6
7
7
export interface ErrorType {
@@ -11,14 +11,31 @@ export interface ErrorType {
11
11
}
12
12
describe ( 'StatusNetworkService' , ( ) => {
13
13
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
+ } ;
15
18
16
19
beforeEach ( ( ) => {
17
- TestBed . configureTestingModule ( { } ) ;
20
+ TestBed . configureTestingModule ( {
21
+ providers : [ ToastrService , {
22
+ provide : ToastrService , useValue : toastrServiceStub
23
+ } ]
24
+ } ) ;
18
25
service = TestBed . inject ( StatusNetworkService ) ;
19
26
} ) ;
20
27
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
+
21
35
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 ( ) ;
23
40
} ) ;
24
41
} ) ;
0 commit comments