Lukasz Kalnik, similar to the CoroutineDispatcher, CoroutineScope needs to be injected into the ViewModel (VM) for testing.

The viewModelScope is created within the VM. Therefore, the CoroutineScope is only passed as an argument for test VMs, otherwise the default argument is set to null, and the scope provider extension function created uses the VM's viewModelScope.

Here is how I injected CoroutineScope. I recommend Craig Russell’s post for injecting the CoroutineDispatcher.

Open Sourcer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store