doAfterFragmentInjection

inline fun <FRAGMENT : Fragment> doAfterFragmentInjection(crossinline mockBlock: (FRAGMENT) -> Unit)

Add a callback that is executed right after AndroidInjection.inject. This method is useful for manual dependency injection in tests.

mockBlock will be called with started InstantTaskExecutor that will force immediate execution of tasks in Android Architectural Components. This allows manual creation of ViewState classes. Otherwise, it would throw an exception

Usage:

doAfterFragmentInjection<SampleFragment> { fragment -> val viewModelProvider = SampleViewModel(mockk(), mockk(), SampleViewState()).asProvider() fragment.viewModelFactory = SampleViewModelFactory(viewModelProvider) fragment.someInjectedClass = mockk() }

Parameters

mockBlock

lambda that will be executed right after Fragment will be injected.