Hello all, I am attempting to test a view model wi...
# android
b
Hello all, I am attempting to test a view model with a paging source. The android documentation for such a test lives here: https://developer.android.com/topic/libraries/architecture/paging/test. Their test refers to a function called Flow.asSnapshot on the Flow api. However I get unresolved reference compile error. Example code in reply.
Here is the example the androids docs give:
Copy code
fun test_separators_are_added_every_10_items() = runTest {
  // Create your ViewModel
  val viewModel = MyViewModel(
    myRepository = FakeMyRepository()
  )
  // Get the Flow of PagingData from the ViewModel with the separator transformations applied
  val items: Flow<PagingData<String>> = viewModel.items
                  
  val snapshot: List<String> = items.asSnapshot(coroutineScope = this) {}

  // With the asSnapshot complete, you can now verify that the snapshot
  // has the expected separators  
}
Is there an issue with my kotlin coroutines version, maybe the example code is using a older version?
i
asSnapshot is a method in the
paging-testing
artifact. Did you add a dependency on that artifact? The current version is 3.2.0-alpha06
👍 1