Skip to content

Instantly share code, notes, and snippets.

@zsmb13
Last active June 29, 2022 12:13
Show Gist options
  • Save zsmb13/c9f95d19cacbb04944ce16773e533a2d to your computer and use it in GitHub Desktop.
Save zsmb13/c9f95d19cacbb04944ce16773e533a2d to your computer and use it in GitHub Desktop.
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@get:Rule
val mainDispatcherRule = MainDispatcherRule()
@Test
-fun collectingTest() = coroutineRule.runBlockingTest {
+fun collectingTest() = runTest {
- val collectJob = launch {
+ val collectJob = launch(UnconfinedTestDispatcher()) {
viewModel.state.collect {
// Save collected values somewhere...
}
}
// Emit values and assert on them here...
collectJob.cancel()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment