``` @Test fun `should emit one account, then t...
# test
u
Copy code
@Test
    fun `should emit one account, then two accounts without images`() = runBlockingTest {

        val firstAccount = Account(
            id = MockDataFactory.randomUuid(),
            name = MockDataFactory.randomString(),
            avatar = Image(
                id = MockDataFactory.randomUuid(),
                sizes = listOf(Image.Size.SMALL)
            )
        )

        val secondAccount = Account(
            id = MockDataFactory.randomUuid(),
            name = MockDataFactory.randomString(),
            avatar = Image(
                id = MockDataFactory.randomUuid(),
                sizes = listOf(Image.Size.SMALL)
            )
        )

        val accounts = flow {
            emit(firstAccount)
            delay(100)
            emit(secondAccount)
        }

        val blob = ByteArray(0)

        val response = Either.Right(blob)

        observeAccounts.stub {
            onBlocking { build() } doReturn accounts
        }

        loadImage.stub {
            onBlocking { invoke(any(), any(), any()) } doAnswer { answer ->
                answer.getArgument<(Either<Throwable, ByteArray>) -> Unit>(2)(response)
            }
        }

        vm = buildViewModel()

        vm.state.observeForTesting {

            advanceTimeBy(1000)

            assertEquals(
                expected = listOf(
                    SelectAccountView.AccountView(
                        id = firstAccount.id,
                        name = firstAccount.name,
                        image = blob
                    ),
                    SelectAccountView.AccountView(
                        id = secondAccount.id,
                        name = secondAccount.name,
                        image = blob
                    )
                ),
                actual = vm.state.value
            )
        }

        vm.viewModelScope.cancel()
    }
Why would
advanceTimeBy
not work? Test fails: I receive only the first emission containing the first account. I wonder how to test several live data emissions, each being delayed by some interval.
t
Wow. That is a big test
u
Testing view model 🙂