From c8eed361c22045d1872dd9413864e297cdeca1b4 Mon Sep 17 00:00:00 2001 From: Nick Nallick Date: Mon, 13 Jun 2022 09:32:13 -0600 Subject: [PATCH 1/2] [208] - Add variation of XCTAssertWorkflowLaunched for use with AnyWorkflow --- Sources/SwiftCurrent_Testing/CustomAssertions.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/SwiftCurrent_Testing/CustomAssertions.swift b/Sources/SwiftCurrent_Testing/CustomAssertions.swift index 28f837234..b395b404d 100644 --- a/Sources/SwiftCurrent_Testing/CustomAssertions.swift +++ b/Sources/SwiftCurrent_Testing/CustomAssertions.swift @@ -18,7 +18,16 @@ import UIKit #if !os(watchOS) /// Assert that a workflow was launched and matches the workflow passed in public func XCTAssertWorkflowLaunched(from VC: UIViewController, workflow: Workflow, file: StaticString = #filePath, line: UInt = #line) { + XCTAssertWorkflowLaunched(from: VC, workflow: AnyWorkflow(workflow), file: file, line: line) +} + +/// Assert that a workflow was launched and matches the workflow passed in +public func XCTAssertWorkflowLaunched(from VC: UIViewController, workflow: AnyWorkflow?, file: StaticString = #filePath, line: UInt = #line) { let last = VC.launchedWorkflows.last + guard let workflow = workflow else { + XCTAssertNil(last, "workflow found when none expected", file: file, line: line) + return + } XCTAssertNotNil(last, "No workflow found", file: file, line: line) guard let listenerWorkflow = last, listenerWorkflow.count == workflow.count else { From ce1cb33f2e65f2ec37627cbcc0044479d0475071 Mon Sep 17 00:00:00 2001 From: Nick Nallick Date: Thu, 23 Jun 2022 17:26:23 -0600 Subject: [PATCH 2/2] [208] - Add XCTAssertNoWorkflowLaunched --- Sources/SwiftCurrent_Testing/CustomAssertions.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftCurrent_Testing/CustomAssertions.swift b/Sources/SwiftCurrent_Testing/CustomAssertions.swift index b395b404d..3bb18c384 100644 --- a/Sources/SwiftCurrent_Testing/CustomAssertions.swift +++ b/Sources/SwiftCurrent_Testing/CustomAssertions.swift @@ -23,11 +23,12 @@ public func XCTAssertWorkflowLaunched(from VC: UIViewController, workflow: Wo /// Assert that a workflow was launched and matches the workflow passed in public func XCTAssertWorkflowLaunched(from VC: UIViewController, workflow: AnyWorkflow?, file: StaticString = #filePath, line: UInt = #line) { - let last = VC.launchedWorkflows.last guard let workflow = workflow else { - XCTAssertNil(last, "workflow found when none expected", file: file, line: line) + XCTAssertNoWorkflowLaunched(from: VC, file: file, line: line) return } + + let last = VC.launchedWorkflows.last XCTAssertNotNil(last, "No workflow found", file: file, line: line) guard let listenerWorkflow = last, listenerWorkflow.count == workflow.count else { @@ -45,5 +46,10 @@ public func XCTAssertWorkflowLaunched(from VC: UIViewController, workflow: AnyWo XCTAssert(actual == expected, "Expected type: \(expected), but got: \(actual)", file: file, line: line) } } + +/// Assert that no workflow was launched +public func XCTAssertNoWorkflowLaunched(from VC: UIViewController, file: StaticString = #filePath, line: UInt = #line) { + XCTAssertNil(VC.launchedWorkflows.last, "workflow found when none expected", file: file, line: line) +} #endif #endif