-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setContent variant which returns initial snapshot (#665)
- Loading branch information
1 parent
7a52066
commit 9f63a35
Showing
6 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
mosaic-testing/src/commonTest/kotlin/com/jakewharton/mosaic/testing/TestMosaicTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.jakewharton.mosaic.testing | ||
|
||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.setValue | ||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import com.jakewharton.mosaic.ui.Text | ||
import kotlin.test.Test | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.test.runTest | ||
|
||
class TestMosaicTest { | ||
@Test fun setContentAndSnapshot() = runTest { | ||
runMosaicTest { | ||
var number by mutableIntStateOf(0) | ||
val initial = setContentAndSnapshot { | ||
Text("The number is: $number") | ||
LaunchedEffect(Unit) { | ||
number = 1 | ||
} | ||
} | ||
|
||
// Defer to allow effect to run. | ||
delay(10.milliseconds) | ||
|
||
assertThat(initial).isEqualTo("The number is: 0") | ||
assertThat(awaitSnapshot()).isEqualTo("The number is: 1") | ||
} | ||
} | ||
|
||
@Test fun setContentThenSnapshot() = runTest { | ||
runMosaicTest { | ||
var number by mutableIntStateOf(0) | ||
setContent { | ||
Text("The number is: $number") | ||
LaunchedEffect(Unit) { | ||
number = 1 | ||
} | ||
} | ||
|
||
// Defer to allow effect to run. | ||
delay(10.milliseconds) | ||
|
||
assertThat(awaitSnapshot()).isEqualTo("The number is: 1") | ||
} | ||
} | ||
} |