https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

coroutinedispatcher

11/18/2020, 10:31 PM
Didn’t find much in Google about this. I am trying to test this function which uses
SharedFlow
but I am getting an
IllegalStateException: This job has not completed yet
. It’s basically pretty easy because I commented out the rest of the code for now:
Copy code
fun registerNewUser(email: String, password: String, hint: String) {
        viewModelScope.launch { _state.emit(State.Loading) }
        // commented out for the moment just to make sure it's not the rest of the code that is failing the test
    }
And the test:
Copy code
@Test
    fun `starting registration process will set the state immediately to loading`() =
        runBlockingTest(testCoroutineDispatcher) {
            registerViewModel.registerNewUser("anyEmail", "anyPassword", "anyHint")

 ~           assertEquals(registerViewModel.state.first(), RegisterViewModel.State.Loading)
        }
Versions:
Copy code
coroutines: "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1",
            coroutines_android : "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1",
            coroutines_test: "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.1"
Probably doing something wrong, but not sure what. Any ideas/input?
Or am I supposed to completely fake the behaviour of
SharedFlow
👀
In case I would replace it with a
StateFlow
just checking the
_state.value
would work
3 Views