Skip to content

Instantly share code, notes, and snippets.

@sauravexodus
Created May 12, 2018 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauravexodus/b0e8d5555df40792f90a5ddc37c1f31a to your computer and use it in GitHub Desktop.
Save sauravexodus/b0e8d5555df40792f90a5ddc37c1f31a to your computer and use it in GitHub Desktop.
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