-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow recording state without MavericksView for Composables #544
Comments
Another use case would be, if you use a ViewModel in a composable, but not in a |
yes, we will likely need to do something like this, but it would be a fairly large update and won't happen immediately |
@elihart Any updates on this? Being able to mock a mavericks view model in a compose test would be incredibly helpful |
In terms of recording viewmodel state, I believe that is already possible. The The documentation doesn't reflect this exactly, but the mock printer script should generally work with viewmodels created and used in Compose UI (if that isn't the case, please raise the exact issue and we can suggest a fix). The other part, I believe, is how to apply the mock state. With Fragments we had a system for declaring mock states and using them in tests, but with Compose UI there isn't anything as cohesive. You would have to create the viewmodel manually with the mock state for a test, which should work fine. |
When using Mavericks with Compose, the UI is not extending from
MavericksView
. This means the existing mock recording code usingmavericks-mocking
won't work. Could we have this functionality moved from the View layer into the ViewModel layer?As ViewModels are responsible for emitting UI state, this seems like a reasonable change - and it would enable the recording to happen even when the UI is composed of Composables. This would make testing with Compose driven apps easier, as we would have the ability to record potentially complicated state emitted from our ViewModels for use in even the most focused Composable tests (eg, using the
createComposeRule()
andcomposeTestRule.setContent
.It would also be ok if, at first, we had to use a "flow test" (
createAndroidComposeRule<SomeActivity>()
) to enable this functionality - but I think it would be idea if both cases were supported - testing via anActivity
and testing theComposable
directly.https://airbnb.io/mavericks/#/mocking
The text was updated successfully, but these errors were encountered: