Skip to content

Instantly share code, notes, and snippets.

@sean7218
Created December 7, 2024 21:21
Show Gist options
  • Save sean7218/479d90fdfa9427baa72961624ae7eea1 to your computer and use it in GitHub Desktop.
Save sean7218/479d90fdfa9427baa72961624ae7eea1 to your computer and use it in GitHub Desktop.
TestScheduler with ActionCreator
extension SandboxActionCreator where S == TestScheduler {
convenience init(environment: PluginEnvironment) {
self.init(environment: environment, scheduler: TestScheduler())
}
}
class SandboxPluginTests: XCTestCase {
func test() {
enum CustomError: Error {
case timeout
case other
}
enum CustomAction: Equatable {
case good
case bad
}
let subject = PassthroughSubject<CustomAction, CustomError>()
let scheduler = TestScheduler(initialClock: 0)
let publisher: AnyPublisher<CustomAction, CustomError> = subject
.timeout(3, scheduler: scheduler, customError: { CustomError.timeout })
.print("|><|")
.eraseToAnyPublisher()
print(">> 3.", scheduler.now)
let results = scheduler.start(
configuration: .init(pausedOnStart: false,
created: 100,
subscribed: 200,
cancelled: 900,
subscriberOptions: TestableSubscriberOptions.default)
) { publisher }
print(">> 5.", scheduler.now)
XCTAssertEqual(results.recordedOutput, [
(200, .subscription), (203, .completion(.failure(.timeout)))
])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment