|
221 | 221 | ) {
|
222 | 222 | var receivedActions: [Action] = []
|
223 | 223 |
|
224 |
| - var cancellables: [Disposable] = [] |
| 224 | + var cancellables: [String: [Disposable]] = [:] |
225 | 225 |
|
226 | 226 | func runReducer(action: Action) {
|
| 227 | + let actionKey = debugCaseOutput(action) |
| 228 | + |
227 | 229 | let effect = self.reducer.run(&self.state, action, self.environment)
|
228 | 230 | var isComplete = false
|
229 | 231 | var cancellable: Disposable?
|
|
233 | 235 | case .completed, .interrupted:
|
234 | 236 | isComplete = true
|
235 | 237 | guard let cancellable = cancellable else { return }
|
236 |
| - cancellables.removeAll(where: { $0 === cancellable }) |
| 238 | + cancellables[actionKey]?.removeAll(where: { $0 === cancellable }) |
237 | 239 | case let .value(value):
|
238 | 240 | receivedActions.append(value)
|
239 | 241 | }
|
240 | 242 | }
|
241 | 243 | if !isComplete, let cancellable = cancellable {
|
242 |
| - cancellables.append(cancellable) |
| 244 | + cancellables[actionKey] = cancellables[actionKey] ?? [] |
| 245 | + cancellables[actionKey]?.append(cancellable) |
243 | 246 | }
|
244 | 247 | }
|
245 | 248 |
|
|
334 | 337 | line: line
|
335 | 338 | )
|
336 | 339 | }
|
337 |
| - if !cancellables.isEmpty { |
| 340 | + |
| 341 | + let unfinishedActions = cancellables.filter { !$0.value.isEmpty }.map { $0.key } |
| 342 | + if unfinishedActions.count > 0 { |
| 343 | + let initiatingActions = unfinishedActions.map { "• \($0)" }.joined(separator: "\n") |
| 344 | + let pluralSuffix = unfinishedActions.count == 1 ? "" : "s" |
| 345 | + |
338 | 346 | _XCTFail(
|
339 | 347 | """
|
340 | 348 | Some effects are still running. All effects must complete by the end of the assertion.
|
341 | 349 |
|
342 |
| - This can happen for a few reasons: |
| 350 | + The effects that are still running were started by the following action\(pluralSuffix): |
| 351 | +
|
| 352 | + \(initiatingActions) |
| 353 | +
|
| 354 | + To fix you need to inspect the effects returned from the above action\(pluralSuffix) and \ |
| 355 | + make sure that all of them are completed by the end of your assertion. There are a few \ |
| 356 | + reasons why your effects may not have completed: |
343 | 357 |
|
344 | 358 | • If you are using a scheduler in your effect, then make sure that you wait enough time \
|
345 | 359 | for the effect to finish. If you are using a test scheduler, then make sure you advance \
|
|
0 commit comments