Skip to content

Commit

Permalink
Fixed enforceOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert committed Jun 16, 2022
1 parent 74c8408 commit 5167990
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

Expand Down Expand Up @@ -114,5 +114,5 @@ func testNonEquatableFailure() {

## Upcoming Features

- Enforcing order of expectations
- Support for working with `Scheduler`s to avoid relying on timeouts

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class PublisherExpectation<UpstreamPublisher: Publisher> {
/// - 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Never>()
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<String, Never>("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() {
Expand Down

0 comments on commit 5167990

Please sign in to comment.