Hi, I am trying to write my first unit test for my...
# orbit-mvi
r
Hi, I am trying to write my first unit test for my viewmodel but it doesnt work
Here’s my test
Copy code
@Test
fun firstTest() = runBlocking {

    // given
    coEvery { repo.getServerTime() } returns Result.success(aDate)
    coEvery { repo.getUser() } returns ApiResultWrapper.Success(aUserResponse)
    every { prefs.getPass(any()) } returns null

    // when
    val testSubject = HubViewModel(authService, repo, prefs).test(HubState(loading = true))
    testSubject.runOnCreate()
    testSubject.testIntent {
        loadUser()
    }

    // then
    testSubject.assert(HubState(loading = true)) {
        states(
            { copy(loading = false) }
        )
    }
}
It just runs indefinately, never completing
m
could you show us your
HubViewModel
snippet code?
r
Copy code
class HubViewModel(
    private val authService: AuthService,
    private val repo: MerlinRepository,
    private val prefs: Preferences,
) : BaseVM(), ContainerHost<HubState, NavigationEvent> {

    override val container: Container<HubState, NavigationEvent> =
        container(HubState(loading = true)) {
            loadUser()
        }

    fun loadUser() = intent {
        repeatOnSubscription {
            val serverTimeResult = repo.getServerTime()
            if (serverTimeResult.isFailure) {
                postSideEffect(GlobalNavigationEvent.NavigateToGenericError)
            }
            when (val response = repo.getUser()) {
a
could be an issue with
repeatOnSubscription
@Mikolaj Leszczynski?
r
let me try and remove it….
yep, test no longer hangs
🙏 1
m
Looks like
repeatOnSubscription
might never be subscribing in unit tests! I’ll file an issue.
🙏 1