|
265 | 265 | if expectedState != actualState {
|
266 | 266 | let diff =
|
267 | 267 | debugDiff(expectedState, actualState)
|
268 |
| - .map { ": …\n\n\($0.indent(by: 4))\n\n(Expected: −, Actual: +)" } |
269 |
| - ?? "" |
| 268 | + .map { "\($0.indent(by: 4))\n\n(Expected: −, Actual: +)" } |
| 269 | + ?? """ |
| 270 | + Expected: |
| 271 | + \(String(describing: expectedState).indent(by: 2)) |
| 272 | +
|
| 273 | + Actual: |
| 274 | + \(String(describing: actualState).indent(by: 2)) |
| 275 | + """ |
| 276 | + |
270 | 277 | _XCTFail(
|
271 | 278 | """
|
272 |
| - State change does not match expectation\(diff) |
| 279 | + State change does not match expectation: … |
| 280 | +
|
| 281 | + \(diff) |
273 | 282 | """,
|
274 |
| - file: step.file, line: step.line |
| 283 | + file: step.file, |
| 284 | + line: step.line |
275 | 285 | )
|
276 | 286 | }
|
277 | 287 | }
|
|
291 | 301 | )
|
292 | 302 | }
|
293 | 303 | viewStore.send(action)
|
294 |
| - update(&expectedState) |
| 304 | + do { |
| 305 | + try update(&expectedState) |
| 306 | + } catch { |
| 307 | + _XCTFail("Threw error: \(error)", file: step.file, line: step.line) |
| 308 | + } |
295 | 309 | expectedStateShouldMatch(actualState: toLocalState(snapshotState))
|
296 | 310 |
|
297 | 311 | case let .receive(expectedAction, update):
|
|
308 | 322 | if expectedAction != receivedAction {
|
309 | 323 | let diff =
|
310 | 324 | debugDiff(expectedAction, receivedAction)
|
311 |
| - .map { ": …\n\n\($0.indent(by: 4))\n\n(Expected: −, Actual: +)" } |
312 |
| - ?? "" |
| 325 | + .map { "\($0.indent(by: 4))\n\n(Expected: −, Received: +)" } |
| 326 | + ?? """ |
| 327 | + Expected: |
| 328 | + \(String(describing: expectedState).indent(by: 2)) |
| 329 | +
|
| 330 | + Received: |
| 331 | + \(String(describing: receivedAction).indent(by: 2)) |
| 332 | + """ |
| 333 | + |
313 | 334 | _XCTFail(
|
314 | 335 | """
|
315 |
| - Received unexpected action\(diff) |
| 336 | + Received unexpected action: … |
| 337 | +
|
| 338 | + \(diff) |
316 | 339 | """,
|
317 | 340 | file: step.file, line: step.line
|
318 | 341 | )
|
319 | 342 | }
|
320 |
| - update(&expectedState) |
| 343 | + do { |
| 344 | + try update(&expectedState) |
| 345 | + } catch { |
| 346 | + _XCTFail("Threw error: \(error)", file: step.file, line: step.line) |
| 347 | + } |
321 | 348 | expectedStateShouldMatch(actualState: toLocalState(state))
|
322 | 349 | snapshotState = state
|
323 | 350 |
|
|
333 | 360 | file: step.file, line: step.line
|
334 | 361 | )
|
335 | 362 | }
|
336 |
| - work(&self.environment) |
| 363 | + do { |
| 364 | + try work(&self.environment) |
| 365 | + } catch { |
| 366 | + _XCTFail("Threw error: \(error)", file: step.file, line: step.line) |
| 367 | + } |
337 | 368 |
|
338 | 369 | case let .do(work):
|
339 | 370 | if !receivedActions.isEmpty {
|
|
347 | 378 | file: step.file, line: step.line
|
348 | 379 | )
|
349 | 380 | }
|
350 |
| - work() |
| 381 | + do { |
| 382 | + try work() |
| 383 | + } catch { |
| 384 | + _XCTFail("Threw error: \(error)", file: step.file, line: step.line) |
| 385 | + } |
351 | 386 | }
|
352 | 387 | }
|
353 | 388 |
|
|
456 | 491 | _ action: LocalAction,
|
457 | 492 | file: StaticString = #file,
|
458 | 493 | line: UInt = #line,
|
459 |
| - _ update: @escaping (inout LocalState) -> Void = { _ in } |
| 494 | + _ update: @escaping (inout LocalState) throws -> Void = { _ in } |
460 | 495 | ) -> Step {
|
461 | 496 | Step(.send(action, update), file: file, line: line)
|
462 | 497 | }
|
|
473 | 508 | _ action: Action,
|
474 | 509 | file: StaticString = #file,
|
475 | 510 | line: UInt = #line,
|
476 |
| - _ update: @escaping (inout LocalState) -> Void = { _ in } |
| 511 | + _ update: @escaping (inout LocalState) throws -> Void = { _ in } |
477 | 512 | ) -> Step {
|
478 | 513 | Step(.receive(action, update), file: file, line: line)
|
479 | 514 | }
|
|
486 | 521 | public static func environment(
|
487 | 522 | file: StaticString = #file,
|
488 | 523 | line: UInt = #line,
|
489 |
| - _ update: @escaping (inout Environment) -> Void |
| 524 | + _ update: @escaping (inout Environment) throws -> Void |
490 | 525 | ) -> Step {
|
491 | 526 | Step(.environment(update), file: file, line: line)
|
492 | 527 | }
|
|
498 | 533 | public static func `do`(
|
499 | 534 | file: StaticString = #file,
|
500 | 535 | line: UInt = #line,
|
501 |
| - _ work: @escaping () -> Void |
| 536 | + _ work: @escaping () throws -> Void |
502 | 537 | ) -> Step {
|
503 | 538 | Step(.do(work), file: file, line: line)
|
504 | 539 | }
|
505 | 540 |
|
506 | 541 | fileprivate enum StepType {
|
507 |
| - case send(LocalAction, (inout LocalState) -> Void) |
508 |
| - case receive(Action, (inout LocalState) -> Void) |
509 |
| - case environment((inout Environment) -> Void) |
510 |
| - case `do`(() -> Void) |
| 542 | + case send(LocalAction, (inout LocalState) throws -> Void) |
| 543 | + case receive(Action, (inout LocalState) throws -> Void) |
| 544 | + case environment((inout Environment) throws -> Void) |
| 545 | + case `do`(() throws -> Void) |
511 | 546 | }
|
512 | 547 | }
|
513 | 548 |
|
|
0 commit comments