https://kotlinlang.org logo
#orbit-mvi
Title
# orbit-mvi
m

Mikolaj Leszczynski

11/06/2023, 2:32 PM
@Jon Bailey In your example for the new testing framework not working, you are using the same
scope
to create the container and to run the test. This will create a deadlock. The solution here is to use
backgroundScope
. Here is a rewritten version that should work (not tested):
Copy code
data class ExampleState(val value: String = "")
    class ExampleContainerHost(scope: CoroutineScope):
        ContainerHost<ExampleState, Unit> {

        // create a container
        override val container = scope.container<ExampleState, Unit>(ExampleState())

        fun doSomethingUseful() = intent {
            reduce { ExampleState("foo") }
        }
    }

    @Test
    fun exampleTest() = runTest {
        ExampleContainerHost(this.backgroundScope).test(this) { // < --- Pass backgroundScope to orbit factory f-n
            expectInitialState()
            containerHost.doSomethingUseful()

            expectState { copy("foo") }
        }
    }
I guess this is mostly a missing documentation issue 🙂 I'll try to fix this soon