1
1
import { matcherHint , printExpected , printReceived } from 'jest-matcher-utils' ;
2
- //tslint:disable-next-line:no-require-imports
3
- import isEqualWith = require( 'lodash.isequalwith' ) ;
2
+ import { toEqual } from 'jest-matchers/build/matchers' ;
4
3
import { SubscriptionLog } from 'rxjs/testing/SubscriptionLog' ;
5
4
import { TestMessage } from '../message/TestMessage' ;
6
5
import { constructObservableMarble } from './constructObservableMarble' ;
7
6
import { constructSubscriptionMarble } from './constructSubscriptionMarble' ;
8
7
9
- const observableMarbleAssert = ( source : Array < TestMessage > ) => ( expected : Array < TestMessage > ) => {
8
+ const toEqulAssert = toEqual . bind ( { expand : false } ) ;
9
+
10
+ const observableMarbleAssert = < T = string > ( source : Array < TestMessage < T > > | Readonly < Array < TestMessage < T > > > ) => (
11
+ expected : Array < TestMessage < T > > | Readonly < Array < TestMessage < T > > >
12
+ ) => {
10
13
if ( ! Array . isArray ( expected ) ) {
11
14
throw new Error ( 'Expected value is not array' ) ;
12
15
}
13
16
14
17
const sourceMarble = constructObservableMarble ( source ) ;
15
18
const expectedMarble = constructObservableMarble ( expected ) ;
16
19
17
- if ( ! isEqualWith ( sourceMarble , expectedMarble ) ) {
18
- throw new Error ( 'unmatch' ) ;
20
+ const asserted = toEqulAssert ( source , expected ) ;
21
+
22
+ if ( ! asserted . pass ) {
23
+ const description = `
24
+ ${ printReceived ( `Source: ${ sourceMarble } ` ) }
25
+ ${ printExpected ( `Expected: ${ expectedMarble } ` ) }
26
+
27
+ ${ asserted . message ( ) }
28
+ ` ;
29
+ throw new Error ( description ) ;
19
30
}
20
31
} ;
21
32
@@ -27,25 +38,29 @@ const subscriptionMarbleAssert = (source: SubscriptionLog) => (expected: Subscri
27
38
const sourceMarble = constructSubscriptionMarble ( source ) ;
28
39
const expectedMarble = constructSubscriptionMarble ( expected ) ;
29
40
30
- if (
31
- sourceMarble . marbleString !== expectedMarble . marbleString ||
32
- sourceMarble . frameString !== expectedMarble . frameString
33
- ) {
34
- const description = ` ${ matcherHint ( ' to equal ' , JSON . stringify ( source ) , JSON . stringify ( expected ) ) }
41
+ const asserted = toEqulAssert ( sourceMarble , expectedMarble ) ;
42
+
43
+ if ( ! asserted . pass ) {
44
+ const description = `
45
+ ${ matcherHint ( ' to equal ' , JSON . stringify ( source ) , JSON . stringify ( expected ) ) }
35
46
36
- ${ printReceived ( `Source: ${ sourceMarble . marbleString } ` ) }
37
- ${ printReceived ( ` ${ sourceMarble . frameString } ` ) }
38
- ${ printExpected ( `Expected: ${ expectedMarble . marbleString } ` ) }
39
- ${ printExpected ( ` ${ expectedMarble . frameString } ` ) }
47
+ ${ printReceived ( `Source: ${ sourceMarble . marbleString } ` ) }
48
+ ${ printReceived ( ` ${ sourceMarble . frameString } ` ) }
49
+ ${ printExpected ( `Expected: ${ expectedMarble . marbleString } ` ) }
50
+ ${ printExpected ( ` ${ expectedMarble . frameString } ` ) }
40
51
` ;
41
52
42
53
throw new Error ( description ) ;
43
54
}
44
55
} ;
45
56
46
- function marbleAssert ( source : SubscriptionLog ) : { to : { equal ( expected : SubscriptionLog ) : void } } ;
47
- function marbleAssert ( source : Array < TestMessage > ) : { to : { equal ( expected : Array < TestMessage > ) : void } } ;
48
- function marbleAssert ( source : SubscriptionLog | Array < TestMessage > ) : { to : { equal ( expected : object ) : void } } {
57
+ function marbleAssert < T = void > ( source : SubscriptionLog ) : { to : { equal ( expected : SubscriptionLog ) : void } } ;
58
+ function marbleAssert < T = string > (
59
+ source : Array < TestMessage < T > > | Readonly < Array < TestMessage < T > > >
60
+ ) : { to : { equal ( expected : Array < TestMessage < T > > | Readonly < Array < TestMessage < T > > > ) : void } } ;
61
+ function marbleAssert < T = string > (
62
+ source : SubscriptionLog | Array < TestMessage < T > > | Readonly < Array < TestMessage < T > > >
63
+ ) : { to : { equal ( expected : object ) : void } } {
49
64
const isSourceArray = Array . isArray ( source ) ;
50
65
const isSourceSubscription = source instanceof SubscriptionLog ;
51
66
@@ -57,7 +72,7 @@ function marbleAssert(source: SubscriptionLog | Array<TestMessage>): { to: { equ
57
72
to : {
58
73
equal : isSourceSubscription
59
74
? subscriptionMarbleAssert ( source as SubscriptionLog )
60
- : observableMarbleAssert ( source as Array < TestMessage > )
75
+ : observableMarbleAssert ( source as any )
61
76
}
62
77
} ;
63
78
}
0 commit comments