Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve testing #6

Open
SwiftyJunnos opened this issue Nov 14, 2024 · 0 comments
Open

Improve testing #6

SwiftyJunnos opened this issue Nov 14, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@SwiftyJunnos
Copy link
Member

SwiftyJunnos commented Nov 14, 2024

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.

@SwiftyJunnos SwiftyJunnos self-assigned this Nov 14, 2024
@SwiftyJunnos SwiftyJunnos added the enhancement New feature or request label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant