receive(_:timeout:assert:fileID:file:line:column:)
Asserts an action was received from an effect that matches a predicate, and asserts how the state changes.
@MainActor func receive(_ isMatching: (_ action: Action) -> Bool, timeout nanoseconds: UInt64? = nil, assert updateStateToExpectedResult: ((_ state: inout State) throws -> Void)? = nil, fileID: StaticString = #fileID, file filePath: StaticString = #filePath, line: UInt = #line, column: UInt = #column) async
Parameters
- isMatching
A closure that attempts to match an action. If it returns
false
, a test failure is reported.- nanoseconds
The amount of time to wait for the expected action.
- updateStateToExpectedResult
A closure that asserts state changed by sending the action to the store. The mutable state sent to this closure must be modified to match the state of the store after processing the given action. Do not provide a closure if no change is expected.
- fileID
The fileID.
- filePath
The filePath.
- line
The line.
- column
The column.
This method is similar to receive(_:timeout:assert:fileID:file:line:column:)-8zqxk
, except it allows you to assert that an action was received that matches a predicate instead of a case key path:
await store.send(.buttonTapped)
await store.receive {
guard case .response(.success) = $0 else { return false }
return true
} assert: {
store.count = 42
}
When the store’s exhaustivity
is set to anything other than off
, a grey information box will show next to the store.receive
line in Xcode letting you know what data was in the effect that you chose not to assert on.
If you only want to check that a particular action case was received, then you might find the receive(_:timeout:assert:fileID:file:line:column:)-53wic
overload of this method more useful.