How do you mock `rememberLauncherForActivityResult...
# compose
p
How do you mock
rememberLauncherForActivityResult
in Compose? With
registerForActivityResult
you could send in a
registry
parameter to prevent the real implementation from being called in UI-tests. However this is missing for the Compose equivalent.
n
Compose
@Preview
now provides a
LocalActivityResultRegistryOwner
that allows you to preview Composables that use APIs like
rememberLauncherForActivityResult()
that depend on that owner existing. (Ib13d1, b/185693006)
oh sorry I thought it was for the Preview
i
Just provide your own registry via
LocalActivittResultRegistryOwner
p
How? I tried:
Copy code
val registry = registryWrapper.activityResultRegistry

if (registry != null) {
    LocalActivityResultRegistryOwner.provides {
        registry
    }
}
val current = LocalActivityResultRegistryOwner.current?.activityResultRegistry

require(registry == current)
where registry is my mocked registry (i debugged to check that it is not null).
rememberLauncherForActivityResult
Will still not take my mocked registry and calling
.current
does not return my mocked registry
That's what makes that value you provide available to everything under that hierarchy
p
It works now thanks for the help
335 Views