Created
November 1, 2023 22:55
-
-
Save aduuub/a84b9994257d8dcfd8393baf25efc65a to your computer and use it in GitHub Desktop.
ResultPublishers Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
// Depends on SP: https://github.com/albertbori/TestableCombinePublishers | |
import TestableCombinePublishers | |
final class ResultPublisherTests: XCTestCase { | |
func testSuccess() { | |
ResultPublisher<String, Error> { [weak self] in | |
self?.basicSuccess(completion: $0) | |
} | |
.expect("success string") | |
.waitForExpectations(timeout: 1) | |
} | |
func testFailure() { | |
ResultPublisher<String, Error> { [weak self] in | |
self?.basicFailure(completion: $0) | |
} | |
.expectFailure() | |
.waitForExpectations(timeout: 1) | |
} | |
func testMultiOutput() { | |
ResultPublisher<String, Error> { [weak self] in | |
self?.multiSuccess(completion: $0) | |
} | |
.expectExactly(2, { XCTAssertEqual("success string", $0) }) | |
.waitForExpectations(timeout: 1) | |
} | |
// MARK: - HELPERS | |
private func basicFailure(completion: @escaping (Result<String, Error>) -> Void) { | |
completion(.failure(NSError(domain: "test", code: 1))) | |
} | |
private func basicSuccess(completion: @escaping (Result<String, Error>) -> Void) { | |
completion(.success("success string")) | |
} | |
private func multiSuccess(completion: @escaping (Result<String, Error>) -> Void) { | |
completion(.success("success string")) | |
completion(.success("success string")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment