@@ -1174,30 +1174,18 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
1174
1174
) {
1175
1175
self . receiveAction (
1176
1176
matching: { expectedAction == $0 } ,
1177
- failureMessage: " Expected to receive an action \( expectedAction) , but didn't get one. " ,
1178
- onReceive: { receivedAction in
1179
- if expectedAction != receivedAction {
1180
- let difference = TaskResultDebugging . $emitRuntimeWarnings. withValue ( false ) {
1181
- diff ( expectedAction, receivedAction, format: . proportional)
1182
- . map { " \( $0. indent ( by: 4 ) ) \n \n (Expected: −, Received: +) " }
1183
- ?? """
1184
- Expected:
1185
- \( String ( describing: expectedAction) . indent ( by: 2 ) )
1186
-
1187
- Received:
1188
- \( String ( describing: receivedAction) . indent ( by: 2 ) )
1189
- """
1190
- }
1191
-
1192
- XCTFailHelper (
1177
+ failureMessage: #"Expected to receive an action " \#( expectedAction) ", but didn't get one."# ,
1178
+ unexpectedActionDescription: { receivedAction in
1179
+ TaskResultDebugging . $emitRuntimeWarnings. withValue ( false ) {
1180
+ diff ( expectedAction, receivedAction, format: . proportional)
1181
+ . map { " \( $0. indent ( by: 4 ) ) \n \n (Expected: −, Received: +) " }
1182
+ ?? """
1183
+ Expected:
1184
+ \( String ( describing: expectedAction) . indent ( by: 2 ) )
1185
+
1186
+ Received:
1187
+ \( String ( describing: receivedAction) . indent ( by: 2 ) )
1193
1188
"""
1194
- Received unexpected action: …
1195
-
1196
- \( difference)
1197
- """ ,
1198
- file: file,
1199
- line: line
1200
- )
1201
1189
}
1202
1190
} ,
1203
1191
updateStateToExpectedResult,
@@ -1231,22 +1219,11 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
1231
1219
) {
1232
1220
self . receiveAction (
1233
1221
matching: matching,
1234
- failureMessage: " Expected to receive a matching action , but didn't get one. " ,
1235
- onReceive : { receivedAction in
1222
+ failureMessage: " Expected to receive an action matching predicate , but didn't get one. " ,
1223
+ unexpectedActionDescription : { receivedAction in
1236
1224
var action = " "
1237
1225
customDump ( receivedAction, to: & action, indent: 2 )
1238
- XCTFailHelper (
1239
- """
1240
- Received action without asserting on payload:
1241
-
1242
- \( action)
1243
- """ ,
1244
- overrideExhaustivity: self . exhaustivity == . on
1245
- ? . off( showSkippedAssertions: true )
1246
- : self . exhaustivity,
1247
- file: file,
1248
- line: line
1249
- )
1226
+ return action
1250
1227
} ,
1251
1228
updateStateToExpectedResult,
1252
1229
file: file,
@@ -1277,22 +1254,11 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
1277
1254
) {
1278
1255
self . receiveAction (
1279
1256
matching: { casePath. extract ( from: $0) != nil } ,
1280
- failureMessage: " Expected to receive a matching action , but didn't get one. " ,
1281
- onReceive : { receivedAction in
1257
+ failureMessage: " Expected to receive an action matching case path , but didn't get one. " ,
1258
+ unexpectedActionDescription : { receivedAction in
1282
1259
var action = " "
1283
1260
customDump ( receivedAction, to: & action, indent: 2 )
1284
- XCTFailHelper (
1285
- """
1286
- Received action without asserting on payload:
1287
-
1288
- \( action)
1289
- """ ,
1290
- overrideExhaustivity: self . exhaustivity == . on
1291
- ? . off( showSkippedAssertions: true )
1292
- : self . exhaustivity,
1293
- file: file,
1294
- line: line
1295
- )
1261
+ return action
1296
1262
} ,
1297
1263
updateStateToExpectedResult,
1298
1264
file: file,
@@ -1569,16 +1535,14 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
1569
1535
private func receiveAction(
1570
1536
matching predicate: ( Action ) -> Bool ,
1571
1537
failureMessage: @autoclosure ( ) -> String ,
1572
- onReceive : ( Action ) -> Void ,
1538
+ unexpectedActionDescription : ( Action ) -> String ,
1573
1539
_ updateStateToExpectedResult: ( ( inout ScopedState ) throws -> Void ) ? ,
1574
1540
file: StaticString ,
1575
1541
line: UInt
1576
1542
) {
1577
1543
guard !self . reducer. receivedActions. isEmpty else {
1578
1544
XCTFail (
1579
- """
1580
- Expected to receive an action, but received none.
1581
- """ ,
1545
+ failureMessage ( ) ,
1582
1546
file: file,
1583
1547
line: line
1584
1548
)
@@ -1622,7 +1586,17 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
1622
1586
}
1623
1587
1624
1588
let ( receivedAction, state) = self . reducer. receivedActions. removeFirst ( )
1625
- onReceive ( receivedAction)
1589
+ if !predicate( receivedAction) {
1590
+ XCTFailHelper (
1591
+ """
1592
+ Received unexpected action: …
1593
+
1594
+ \( unexpectedActionDescription ( receivedAction) )
1595
+ """ ,
1596
+ file: file,
1597
+ line: line
1598
+ )
1599
+ }
1626
1600
let expectedState = self . toScopedState ( self . state)
1627
1601
do {
1628
1602
try self . expectedStateShouldMatch (
0 commit comments