Store with TestClock not awaiting when using SnapshotTesting #36
Unanswered
lucianolang
asked this question in
Q&A
Replies: 1 comment
|
@lucianolang The first failing test is suspending here: await store.send(.startTimer).finish()This is going to wait till the timer effect finishes before continuing, which means the advancing is never really happening. If you change it to the following: store.send(.startTimer)You'll get 2 snapshots that I believe match what you want: Meanwhile, the second failing test is creating a let sut = ContentView(store: store.snapshotStore)This is a completely inert store/view that is disconnected from the original store, and so it will always snapshot to the state it was when it was created. Changing the code to instead snapshot things each time seems to fix: await clock.advance(by: .seconds(1))
assertSnapshot(
matching: UIHostingController(
rootView: ContentView(store: store.snapshotStore)
),
as: .image
)
await clock.advance(by: .seconds(4))
assertSnapshot(
matching: UIHostingController(
rootView: ContentView(store: store.snapshotStore)
),
as: .image
)Since this doesn't seem like a bug with the library, I'm going to convert to a discussion. |
0 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.
Description
There seems to be an issue with the Store when using a TestClock, the view doesn't react to timer ticks unless we assert for state mutation and recreate the view and the store.
Current versions:
swift-clocks 1.0.2
swift-composable-architecture 1.10.4
swift-snapshot-testing 1.16.0
Checklist
mainbranch of this package.Expected behavior
These tests should pass
Actual behavior
These tests are the only ones that I'm able to make work
Steps to reproduce
Find here the project:
clockTests.zip
Thanks in advance
swift-clocks version information
1.0.2
Destination operating system
iOS 17.4
Xcode version information
15.3
Swift Compiler version information
All reactions