diff --git a/README.md b/README.md index a0a338e..5f1df97 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,10 @@ func testPublisherFailure() { For a `Publisher` that is expected to emit a value after being acted upon externally ```swift func testLoadablePublisher() { - let expectation = someDataSource.publisher + let test = someDataSource.publisher .expect(someEquatableValue) someDataSource.load() - expectation.waitForExpectations(timeout: 1) + test.waitForExpectations(timeout: 1) } ``` @@ -114,5 +114,5 @@ func testNonEquatableFailure() { ## Upcoming Features -- Enforcing order of expectations +- Support for working with `Scheduler`s to avoid relying on timeouts diff --git a/Sources/TestableCombinePublishers/PublisherExpectation.swift b/Sources/TestableCombinePublishers/PublisherExpectation.swift index 3c810f0..4d2a964 100644 --- a/Sources/TestableCombinePublishers/PublisherExpectation.swift +++ b/Sources/TestableCombinePublishers/PublisherExpectation.swift @@ -48,7 +48,7 @@ public final class PublisherExpectation { /// - file: The calling file. Used for showing context-appropriate unit test failures in Xcode /// - line: The calling line of code. Used for showing context-appropriate unit test failures in Xcode public func waitForExpectations(timeout: TimeInterval, enforceOrder: Bool = false, file: StaticString = #filePath, line: UInt = #line) { - let result = XCTWaiter(delegate: delegate).wait(for: expectations, timeout: timeout, enforceOrder: false) + let result = XCTWaiter(delegate: delegate).wait(for: expectations, timeout: timeout, enforceOrder: enforceOrder) switch result { case .completed: break diff --git a/Tests/TestableCombinePublishersTests/TestableCombinePublishersTests.swift b/Tests/TestableCombinePublishersTests/TestableCombinePublishersTests.swift index f676a00..b71e6df 100644 --- a/Tests/TestableCombinePublishersTests/TestableCombinePublishersTests.swift +++ b/Tests/TestableCombinePublishersTests/TestableCombinePublishersTests.swift @@ -387,23 +387,24 @@ final class TestableCombinePublishersTests: XCTestCase { .waitForExpectations(timeout: 1) } - // TODO: This is currently failing. The expectations should respect sequence, if possible. func testOrderFail() { XCTExpectFailure("Incorrect assertion should fail") - ["cool"] - .publisher + let publisher = PassthroughSubject() + let test: PublisherExpectation = publisher .expectSuccess() .expect("cool") - .waitForExpectations(timeout: 1) + publisher.send("cool") + publisher.send(completion: .finished) + test.waitForExpectations(timeout: 1, enforceOrder: true) } func testDeferredWait() { let currentValueSubject = CurrentValueSubject("cool") - let expectation = currentValueSubject + let test = currentValueSubject .collect(2) .expect(["cool", "neat"]) currentValueSubject.value = "neat" - expectation.waitForExpectations(timeout: 1) + test.waitForExpectations(timeout: 1) } func testMultiThreadedExpectation() {