.debounce doesn't seem to work as expected #920
-
Describe the bug To Reproduce Code here is in When I run the tests with case .todo(index: _, action: .checkboxTapped):
struct CancelDelayId: Hashable { }
return Effect(value: AppAction.todoDelayCompleted)
.delay(for: 1, scheduler: DispatchQueue.main)
.eraseToEffect()
.cancellable(id: CancelDelayId(), cancelInFlight: true) // cancelInFlight They all run as expected. However, changing that to a debounce as described in the video to: case .todo(index: _, action: .checkboxTapped):
struct CancelDelayId: Hashable { }
return Effect(value: AppAction.todoDelayCompleted)
.debounce(id: CancelDelayId(), for: 1, scheduler: DispatchQueue.main) there are errors in the test, all to do with not receiving the expected events. I am fine to move on with the other code and will look to see how things change when the scheduler is introduced, but this seems like a bug with debounce possibly using Expected behavior Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hi @jacobbullock, I believe this is just due to the imprecision of using test expectations for waiting exact amounts of time. The reducer is debouncing for 1 second and we are telling the test suite to wait 1 second so that the effect can get past the debounce. It seems that at the time of recording that episode that worked fine, but now the test suite needs a little more time to wait. If you change the expectation to wait just a bit longer, like say 1.01 seconds: XCTWaiter.wait(for:[self.expectation(description: "wait")], timeout: 1.01) Then the test suite will pass. This all goes to show how imprecise using live schedulers in TCA tests can be, which is why we highly recommend using a test scheduler and that is done in the second half of episode 103. |
Beta Was this translation helpful? Give feedback.
Hi @jacobbullock, I believe this is just due to the imprecision of using test expectations for waiting exact amounts of time. The reducer is debouncing for 1 second and we are telling the test suite to wait 1 second so that the effect can get past the debounce. It seems that at the time of recording that episode that worked fine, but now the test suite needs a little more time to wait.
If you change the expectation to wait just a bit longer, like say 1.01 seconds:
Then the test suite will pass.
This all goes to show how imprecise using live schedulers in TCA tests can be, which is why we highly recommend using a te…