Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

weird Unimplemented: ContinuousClock.now problem #3665

Unanswered
Sevenfortyseven asked this question in Q&A
Discussion options

I'm having issues testing an action that uses the continuousClock dependency.

This is the action I'm trying to test:

   case .syncRunningInfo:
        guard let runningData = state.mtisCampaignRunningData else { return .none }
        if runningData.lastSkipped && runningData.timerStartTime == nil {
          state.shouldPresentSuccessToast = true
          state.$mtisCampaignRunningData.withLock { $0 = nil }
          return .none
        }
        if runningData.lastSkipped {
          state.shouldPresentSuccessToast = true
          state.$mtisCampaignRunningData.withLock { $0?.lastSkipped.toggle() }
        }
        guard let timerStartTime = runningData.timerStartTime else { return .none }
        let secondsAfterSkipping = -timerStartTime.timeIntervalSinceNow.rounded()
        let isExpired = secondsAfterSkipping > Double(state.secondsToWarmup)
        if !isExpired {
          state.secondsToWarmupRemaining = state.secondsToWarmup - Int(secondsAfterSkipping)
          state.dashboardState = .warmup
          return .send(.startTimer)
        } else {
          state.shouldPresentSuccessToast = true
          state.$mtisCampaignRunningData.withLock { $0 = nil }
        }
        return .none

This action optionally triggers:

case .startTimer:
     return .run { send in
       for await _ in self.clock.timer(interval: .seconds(1)) {
         await send(.timerTick)
       }
     }
     .cancellable(id: CancelID.warmupTimer)
     

this action which causes that issue.
this is how my test looks like

 @Test("Timer started 30 seconds ago, the last one was skipped")
    func syncRunningInfoFullPath() async throws {
      let clock = TestClock()
      let thirtySecondsAgo = Date().addingTimeInterval(-30)
      $mtisCampaignRunningData.withLock { $0 = .init(timerStartTime: thirtySecondsAgo, lastSkipped: true) }
      let store = await TestStore(initialState: MountainWaterDashboard.State()) {
        MountainWaterDashboard()
      }
      store.exhaustivity = .off
      await withDependencies {
        $0.continuousClock = clock
      } operation: {
        await store.send(.syncRunningInfo) {
          $0.shouldPresentSuccessToast = true
          $0.dashboardState = .warmup
          $0.secondsToWarmupRemaining = $0.secondsToWarmup - 30
          $0.$mtisCampaignRunningData.withLock { $0?.lastSkipped = false }
        }
        await store.receive(\.startTimer)
        await store.finish()
      }
    }

what am I missing?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.