@@ -1428,7 +1428,12 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
1428
1428
} ( )
1429
1429
return
1430
1430
}
1431
- await self . receiveAction ( timeout: nanoseconds, file: file, line: line)
1431
+ await self . receiveAction (
1432
+ matching: { expectedAction == $0 } ,
1433
+ timeout: nanoseconds,
1434
+ file: file,
1435
+ line: line
1436
+ )
1432
1437
_ = {
1433
1438
self . receive ( expectedAction, assert: updateStateToExpectedResult, file: file, line: line)
1434
1439
} ( )
@@ -1445,7 +1450,6 @@ extension TestStore where ScopedState: Equatable {
1445
1450
/// - Parameters:
1446
1451
/// - isMatching: A closure that attempts to match an action. If it returns `false`, a test
1447
1452
/// failure is reported.
1448
- /// - nanoseconds: The amount of time to wait for the expected action.
1449
1453
/// - updateStateToExpectedResult: A closure that asserts state changed by sending the action to
1450
1454
/// the store. The mutable state sent to this closure must be modified to match the state of
1451
1455
/// the store after processing the given action. Do not provide a closure if no change is
@@ -1612,7 +1616,7 @@ extension TestStore where ScopedState: Equatable {
1612
1616
} ( )
1613
1617
return
1614
1618
}
1615
- await self . receiveAction ( timeout: nanoseconds, file: file, line: line)
1619
+ await self . receiveAction ( matching : isMatching , timeout: nanoseconds, file: file, line: line)
1616
1620
_ = {
1617
1621
self . receive ( isMatching, assert: updateStateToExpectedResult, file: file, line: line)
1618
1622
} ( )
@@ -1666,7 +1670,12 @@ extension TestStore where ScopedState: Equatable {
1666
1670
} ( )
1667
1671
return
1668
1672
}
1669
- await self . receiveAction ( timeout: nanoseconds, file: file, line: line)
1673
+ await self . receiveAction (
1674
+ matching: { actionCase. extract ( from: $0) != nil } ,
1675
+ timeout: nanoseconds,
1676
+ file: file,
1677
+ line: line
1678
+ )
1670
1679
_ = {
1671
1680
self . receive ( actionCase, assert: updateStateToExpectedResult, file: file, line: line)
1672
1681
} ( )
@@ -1722,7 +1731,12 @@ extension TestStore where ScopedState: Equatable {
1722
1731
} ( )
1723
1732
return
1724
1733
}
1725
- await self . receiveAction ( timeout: duration. nanoseconds, file: file, line: line)
1734
+ await self . receiveAction (
1735
+ matching: { actionCase. extract ( from: $0) != nil } ,
1736
+ timeout: duration. nanoseconds,
1737
+ file: file,
1738
+ line: line
1739
+ )
1726
1740
_ = {
1727
1741
self . receive ( actionCase, assert: updateStateToExpectedResult, file: file, line: line)
1728
1742
} ( )
@@ -1821,6 +1835,7 @@ extension TestStore where ScopedState: Equatable {
1821
1835
}
1822
1836
1823
1837
private func receiveAction(
1838
+ matching predicate: ( Action ) -> Bool ,
1824
1839
timeout nanoseconds: UInt64 ? ,
1825
1840
file: StaticString ,
1826
1841
line: UInt
@@ -1832,8 +1847,14 @@ extension TestStore where ScopedState: Equatable {
1832
1847
while !Task. isCancelled {
1833
1848
await Task . detached ( priority: . background) { await Task . yield ( ) } . value
1834
1849
1835
- guard self . reducer. receivedActions. isEmpty
1836
- else { break }
1850
+ switch self . exhaustivity {
1851
+ case . on:
1852
+ guard self . reducer. receivedActions. isEmpty
1853
+ else { return }
1854
+ case . off:
1855
+ guard !self . reducer. receivedActions. contains ( where: { predicate ( $0. action) } )
1856
+ else { return }
1857
+ }
1837
1858
1838
1859
guard start. distance ( to: DispatchTime . now ( ) . uptimeNanoseconds) < nanoseconds
1839
1860
else {
@@ -1861,7 +1882,7 @@ extension TestStore where ScopedState: Equatable {
1861
1882
}
1862
1883
XCTFail (
1863
1884
"""
1864
- Expected to receive an action, but received none \
1885
+ Expected to receive \( self . exhaustivity == . on ? " an action " : " a matching action " ) , but received none \
1865
1886
\( nanoseconds > 0 ? " after \( Double ( nanoseconds) / Double( NSEC_PER_SEC) ) seconds " : " " ) .
1866
1887
1867
1888
\( suggestion)
@@ -1872,9 +1893,6 @@ extension TestStore where ScopedState: Equatable {
1872
1893
return
1873
1894
}
1874
1895
}
1875
-
1876
- guard !Task. isCancelled
1877
- else { return }
1878
1896
}
1879
1897
}
1880
1898
0 commit comments