1
- import { from } from 'rxjs' ;
1
+ import { from , map } from 'rxjs' ;
2
2
import { TestScheduler } from 'rxjs/testing' ;
3
3
import { afterAll , beforeEach , describe , expect , test , vi } from 'vitest' ;
4
4
5
- import { log , logResult } from './log' ;
5
+ import { enableLog , log , logResult } from './log' ;
6
6
7
7
describe ( 'log' , ( ) => {
8
8
let testScheduler ;
@@ -23,16 +23,18 @@ describe('log', () => {
23
23
} ;
24
24
25
25
const triggerVal = {
26
- a : expectedVal . a ,
27
- b : expectedVal . b ,
28
- c : expectedVal . c
26
+ a : ( ) => expectedVal . a ,
27
+ b : ( ) => expectedVal . b ,
28
+ c : ( ) => expectedVal . c ,
29
+ d : ( ) => {
30
+ throw new Error ( 'custom error' ) ;
31
+ }
29
32
} ;
30
33
31
34
const expected = [
32
35
' operators:log:default content a' ,
33
36
' operators:log:default content b' ,
34
- ' operators:log:default content c' ,
35
- ' operators:log:default complete!'
37
+ ' operators:log:default content c'
36
38
] ;
37
39
38
40
const actual = [ ] ;
@@ -41,9 +43,13 @@ describe('log', () => {
41
43
return v ;
42
44
} ) ;
43
45
46
+ enableLog ( 'operators:log:default' ) ;
44
47
testScheduler . run ( ( { cold, expectObservable, flush } ) => {
45
- const stream = cold ( 'a-b-c|' , triggerVal ) . pipe ( log ( 'operators:log:default' ) ) ;
46
- expectObservable ( stream ) . toBe ( 'a-b-c|' , expectedVal ) ;
48
+ const stream = cold ( 'a-b-c-d|' , triggerVal ) . pipe (
49
+ map ( v => v ( ) ) ,
50
+ log ( 'operators:log:default' )
51
+ ) ;
52
+ expectObservable ( stream ) . toBe ( 'a-b-c-#' , expectedVal , new Error ( 'custom error' ) ) ;
47
53
flush ( ) ;
48
54
expect ( actual ) . deep . equal ( expected ) ;
49
55
} ) ;
@@ -65,6 +71,7 @@ describe('log', () => {
65
71
66
72
const triggerVal = [ 'content a' , 'content b' , 'content c' ] ;
67
73
74
+ enableLog ( 'operators:log:result' ) ;
68
75
await logResult ( 'operators:log:result' , from ( triggerVal ) ) ;
69
76
expect ( actual ) . deep . equal ( expectedVal ) ;
70
77
} ) ;
0 commit comments