Testing tasks
#1782
Replies: 1 comment 4 replies
-
Hey @Miiha! Thanks for the report. I don't know what is the correct alternative here, but putting your storage on @MainActor
final class TaskIssueTests: XCTestCase {
func testReceivedParameters() async {
var observedNumbers = Set<Int>()
let store = TestStore(
initialState: Feature.State(),
reducer: Feature(
client: Client(
observe: { @MainActor value in
observedNumbers.insert(value)
return .never
}
)
)
)
let task = await store.send(.task)
XCTAssertEqual(observedNumbers, [1, 2, 3])
await task.cancel()
}
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I stumbled over some swift concurrency quirks while testing a reducer that does some calls to an async dependency which returns an AsyncStream. I know that testing swift concurrency is a delicate problem and maybe I also missing something here.
The issue that appears, is that the calls to the dependency are not 100% reproducible and expecting on the received parameters failes the test.
The following unit test should illustrate the problem, when run e.g. a 100 times.
Same behaviour appears when I model the effect differently, e.g. like this:
Beta Was this translation helpful? Give feedback.
All reactions