@@ -50,9 +50,12 @@ const toHaveSameSession = function (received: jest.Mocked<ReplayContainer>, expe
50
50
return {
51
51
pass,
52
52
message : ( ) =>
53
- `${ this . utils . matcherHint ( 'toHaveSameSession' , undefined , undefined , options ) } \n\n` +
54
- `Expected: ${ pass ? 'not ' : '' } ${ this . utils . printExpected ( expected ) } \n` +
55
- `Received: ${ this . utils . printReceived ( received . session ) } ` ,
53
+ `${ this . utils . matcherHint (
54
+ 'toHaveSameSession' ,
55
+ undefined ,
56
+ undefined ,
57
+ options ,
58
+ ) } \n\n${ this . utils . printDiffOrStringify ( expected , received . session , 'Expected' , 'Received' ) } `,
56
59
} ;
57
60
} ;
58
61
@@ -138,11 +141,18 @@ const toHaveSentReplay = function (
138
141
139
142
let result : CheckCallForSentReplayResult ;
140
143
144
+ const expectedKeysLength = expected ? ( 'sample' in expected ? Object . keys ( expected . sample ) : Object . keys ( expected ) ) . length : 0 ;
145
+
141
146
for ( const currentCall of calls ) {
142
147
result = checkCallForSentReplay . call ( this , currentCall [ 0 ] , expected ) ;
143
148
if ( result . pass ) {
144
149
break ;
145
150
}
151
+
152
+ // stop on the first call where any of the expected obj passes
153
+ if ( result . results . length < expectedKeysLength ) {
154
+ break ;
155
+ }
146
156
}
147
157
148
158
// @ts -ignore use before assigned
@@ -161,10 +171,13 @@ const toHaveSentReplay = function (
161
171
? 'Expected Replay to not have been sent, but a request was attempted'
162
172
: 'Expected Replay to have been sent, but a request was not attempted'
163
173
: `${ this . utils . matcherHint ( 'toHaveSentReplay' , undefined , undefined , options ) } \n\n${ results
164
- . map (
165
- ( { key, expectedVal, actualVal } : Result ) =>
166
- `Expected (key: ${ key } ): ${ pass ? 'not ' : '' } ${ this . utils . printExpected ( expectedVal ) } \n` +
167
- `Received (key: ${ key } ): ${ this . utils . printReceived ( actualVal ) } ` ,
174
+ . map ( ( { key, expectedVal, actualVal } : Result ) =>
175
+ this . utils . printDiffOrStringify (
176
+ expectedVal ,
177
+ actualVal ,
178
+ `Expected (key: ${ key } )` ,
179
+ `Received (key: ${ key } )` ,
180
+ ) ,
168
181
)
169
182
. join ( '\n' ) } `,
170
183
} ;
@@ -197,10 +210,13 @@ const toHaveLastSentReplay = function (
197
210
? 'Expected Replay to not have been sent, but a request was attempted'
198
211
: 'Expected Replay to have last been sent, but a request was not attempted'
199
212
: `${ this . utils . matcherHint ( 'toHaveSentReplay' , undefined , undefined , options ) } \n\n${ results
200
- . map (
201
- ( { key, expectedVal, actualVal } : Result ) =>
202
- `Expected (key: ${ key } ): ${ pass ? 'not ' : '' } ${ this . utils . printExpected ( expectedVal ) } \n` +
203
- `Received (key: ${ key } ): ${ this . utils . printReceived ( actualVal ) } ` ,
213
+ . map ( ( { key, expectedVal, actualVal } : Result ) =>
214
+ this . utils . printDiffOrStringify (
215
+ expectedVal ,
216
+ actualVal ,
217
+ `Expected (key: ${ key } )` ,
218
+ `Received (key: ${ key } )` ,
219
+ ) ,
204
220
)
205
221
. join ( '\n' ) } `,
206
222
} ;
0 commit comments