Using the new Compose typesafe navigation, what’s ...
# compose-android
y
Using the new Compose typesafe navigation, what’s the best way to run a test that depends on the
Route
object in
SavedStateHandle
? For example, I have the following code:
Copy code
private val route = savedStateHandle.toRoute<MyRoute>()
How can I instantiate the
SavedStateHandle
object in my tests? Specifically, what should I provide as a key for the map? I’ve tried code similar to the following, but none of the
Route
properties are being passed :
Copy code
val savedStateHandle = SavedStateHandle(mapOf(MyRoute::class.qualifiedName to fakeRoute))
i
m
is there a way to run this inside regular, junit, unit tests?
I’m getting
android.os.Bundle
methods not mocked error. I have
testOptions.unitTests.isReturnDefaultValues = true
in gradle
i
As seen in the exact documentation of that method, you need to use Robolectric
😞 1
j
Not sure if it is the best idea (as it depends on internals) but we currently mocked the SavedStateHandle using mockk to use it in plain unit tests. Here an example:
i
Now that https://issuetracker.google.com/issues/398265336 is solved, the next alpha of Navigation will let you use
jvmTest
(no Robolectric) with
SavedStateHandle
j
Thx for the heads up. We will try that with the next version.
m
thanks, that is awesome. I used to use similar mockk setup