Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #106 from UrbanCompass/sometests
Browse files Browse the repository at this point in the history
Add test for Fail
  • Loading branch information
russellbstephens authored Nov 19, 2018
2 parents 931aaed + 07d9ef9 commit 2bab48a
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions SnailTests/FailTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,41 @@ class FailTests: XCTestCase {
super.setUp()
subject = Fail(TestError.test)
strings = []
subject?.subscribe(onNext: { [weak self] string in self?.strings?.append(string) })
error = nil
done = nil

subject?.subscribe(
queue: nil,
onNext: { [weak self] in self?.strings?.append($0) },
onError: { self.error = $0 },
onDone: { self.done = true }
)
}

func testOnErrorIsRun() {
XCTAssertEqual((error as? TestError), TestError.test)
}

func testFail() {
subject?
.subscribe(onError: { error in self.error = error })
func testOnNextIsNotRun() {
subject?.on(.next("1"))
XCTAssert(strings?.count == 0)
XCTAssert((error as? TestError) == TestError.test)
XCTAssertEqual(strings?.count, 0)
}

func testOnDoneIsNotRun() {
XCTAssertNil(done)
}

func testFiresStoppedEventOnSubscribe() {
var newError: Error?
done = nil

subject?.subscribe(
onError: { error in newError = error },
onDone: { self.done = true }
)

XCTAssertNotNil(newError as? TestError)
XCTAssertEqual(newError as? TestError, error as? TestError)
XCTAssertNil(done)
}
}

0 comments on commit 2bab48a

Please sign in to comment.