Skip to content

Instantly share code, notes, and snippets.

@zsmb13
Last active June 29, 2022 12:12
Show Gist options
  • Save zsmb13/de5c5b0c6c8aa6af951602fcc8df8ebb to your computer and use it in GitHub Desktop.
Save zsmb13/de5c5b0c6c8aa6af951602fcc8df8ebb to your computer and use it in GitHub Desktop.
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Test
fun loadTasks_loading() = runTest {
// Set Main dispatcher to not run coroutines eagerly, for just this one test
Dispatchers.setMain(StandardTestDispatcher())
// Load the task in the viewmodel
statisticsViewModel.refresh()
// Then progress indicator is shown
assertThat(statisticsViewModel.dataLoading.getOrAwaitValue()).isTrue()
// Execute pending coroutine actions
advanceUntilIdle()
// Then progress indicator is hidden
assertThat(statisticsViewModel.dataLoading.getOrAwaitValue()).isFalse()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment