Created
May 12, 2018 11:02
-
-
Save sauravexodus/b0e8d5555df40792f90a5ddc37c1f31a to your computer and use it in GitHub Desktop.
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
Stubber.register(self.authRepository.signIn) { _ in .just(.failure(error: SignInReactor.ErrorMessage.signInFailed.rawValue)) } | |
let disposeBag = DisposeBag() | |
Observable.of(.signIn(email: self.defaultEmail, password: self.defaultPassword)) | |
.delay(1, scheduler: MainScheduler.instance) | |
.bind(to: self.signInReactor.action) | |
.disposed(by: disposeBag) | |
let states = try? self.signInReactor.state.skip(1).take(2).toBlocking(timeout: 5).toArray() | |
guard let loadingState = states?.first else { | |
fail("It should emit a loading state") | |
return | |
} | |
guard let failureState = states?.last else { | |
fail("It should emit a failure state") | |
return | |
} | |
expect(Stubber.executions(self.authRepository.signIn).count).to(equal(1), description: "It should only call sign in once") | |
expect(loadingState.isLoading).to(equal(true), description: "loading state should have loading as true") | |
expect(failureState.errorMessage).to(equal(SignInReactor.ErrorMessage.signInFailed), description: "Error message should be \(SignInReactor.ErrorMessage.signInFailed.rawValue)") | |
expect(failureState.isLoading).to(equal(false), description: "loading state should have loading as false") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment