Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Created March 17, 2021 17:06
Show Gist options
  • Save igorescodro/893133fc0ffd85b28e2c371974784fb3 to your computer and use it in GitHub Desktop.
Save igorescodro/893133fc0ffd85b28e2c371974784fb3 to your computer and use it in GitHub Desktop.
internal class MyComposableTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun test_TitleIsShownWhenLoaded() {
initComposable(state = MyState.Loaded)
composeTestRule.onNodeWithText("Title").assertIsDisplayed()
}
@Test
fun test_TitleIsNotShownWhenError() {
initComposable(state = MyState.Error)
composeTestRule.onNodeWithText("Title").assertIsNotDisplayed()
}
private fun initComposable(state: MyState) {
composeTestRule.setContent {
MyTheme {
MyComposable(state = state)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment