When testing state updates, we found an issue with timing. Here's the current approach:
func timerUpdatedForDisplaying(testCase: TimerUpdatedForDisplaying) async throws {
sut.pour(.timerProgressed(to: testCase.time))
try await Task.sleep(for: .milliseconds(100))
#expect(sut.displayingMinutes == testCase.expected.minutes)
#expect(sut.displayingSeconds == testCase.expected.seconds)
}
Tests sometimes fail without Task.sleep because it's checking the state too early. Since state updates happen asynchronously, we need to wait a bit to ensure the new values are ready.
Although using Task.sleep works, it's not the most elegant solution. Instead, we could make the tests more reliable by adding a way to check the state right after it updates, like this:
sut.pour(.timerProgressed(to: testCase.time)) { state in
#expect(state.displayingMinutes == testCase.expected.minutes)
}
Adding a test feature for waiting Effect to have actual "effect" needs to be added.
When testing state updates, we found an issue with timing. Here's the current approach:
Tests sometimes fail without
Task.sleepbecause it's checking the state too early. Since state updates happen asynchronously, we need to wait a bit to ensure the new values are ready.Although using
Task.sleepworks, it's not the most elegant solution. Instead, we could make the tests more reliable by adding a way to check the state right after it updates, like this:Adding a test feature for waiting
Effectto have actual "effect" needs to be added.