Replies: 1 comment 5 replies
-
Hey @crayment! let clock = TestClock()
let store = TestStore(initialState: Parent.State(child: Child.State()), reducer: Parent()) {
$0.continuousClock = clock
}
let childTask = Task { // This should inherit `@MainActor` from the test.
await store.send(.child(.task)).finish() // We "classically" await for the send to finish.
}
// We need the above task to run a little. I'm megaYielding for this purpose.
// You need to import TCA as `@_spi(Internals) import ComposableArchitecture`
// to access this helper.
await Task.megaYield()
await store.receive(.child(.hook)) {
$0.child = nil
}
// This one is sync now, as this is a simple `Task`
childTask.cancel() // Would be done by SwiftUI
await clock.advance(by: .seconds(1))
await store.receive(.delayedWork) {
$0.count = 1
}
// We need to await `childTask` cancellation to go through and cancel/release its inner
// `send` for the test to succeed.
await Task.megaYield() On my machine, the test passes, but this is very flakey. |
Beta Was this translation helpful? Give feedback.
5 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.
-
I have written the following failing test that demonstrates some behaviour I found confusing. Was a bit of a gotcha on our code base.
In this sample I found it very confusing that
delayedWork
is never performed. And I'm not even sure the best way to modify this code or our patterns to avoid accidentally creating this type of situation. Would like to avoid the parent having intimate knowledge about how the child is implemented. Hopefully the inline comments and the code below make the issue clear.In our case we have a list of cells representing files. You can upload files which puts a cell in a top section of the list. When the upload completes we remove the uploading cell from the top section and append a new cell to the bottom section representing the new file that now exists on the backend. For unimportant reasons we had a small delay between removing the uploading cell and appending the new file cell.
Beta Was this translation helpful? Give feedback.
All reactions