Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertions for side-effects #212

Open
pakoito opened this issue Mar 11, 2019 · 1 comment
Open

Assertions for side-effects #212

pakoito opened this issue Mar 11, 2019 · 1 comment

Comments

@pakoito
Copy link

pakoito commented Mar 11, 2019

Based off this tweet: https://twitter.com/pacoworks/status/1098377239786221568

fun <T> testSideEffect(f: TestObserver<T>.((T)-> Unit) -> Unit): Unit {
  val obs = TestObserver<T>()
  val sub = PublishSubject.create<T>().apply { subscribe(obs) }
  f(obs) { sub.onNext(it) }
}

fun main() {
    testSideEffect<Int> { consumer ->
        Observable.just(1).doOnNext { consumer(it) }.subscribe()

        assertValueCount(1)
        assertValues(10)
    }
}
@pakoito
Copy link
Author

pakoito commented Mar 11, 2019

It's just a general idea. It could be polished to avoid gotchas such as awaitTerminalEvent() never returning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant