Skip to content

Improve testing #6

Description

@SwiftyJunnos

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions