mirror of
https://github.com/uber/RIBs.git
synced 2026-05-17 12:50:36 +00:00
Make suspend functions callable inside test(worker) { }
We don't need `crossinline` for `testBody`. Usage of cross-inline makes suspend functions non-callable in the test body, which forbids patterns like:
```
test(worker) {
sharedFlow.emit(someValue)
// assert worker processed it
}
```
This commit is contained in:
@@ -190,6 +190,8 @@ class RibCoroutineWorkerTest {
|
||||
assertThat(worker.innerCoroutineCompleted).isFalse()
|
||||
assertThat(worker.onStopRan).isFalse()
|
||||
test(worker) {
|
||||
// Quick check that suspend functions can be called inside this block
|
||||
delay(0)
|
||||
// Assert onStart and inner coroutine started but have not finished (it has delays)
|
||||
assertThat(it.onStartStarted).isTrue()
|
||||
assertThat(it.innerCoroutineStarted).isTrue()
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ import kotlinx.coroutines.test.runCurrent
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
public inline fun <T : RibCoroutineWorker> TestScope.test(
|
||||
worker: T,
|
||||
crossinline testBody: TestScope.(T) -> Unit,
|
||||
testBody: TestScope.(T) -> Unit,
|
||||
) {
|
||||
val dispatcher = StandardTestDispatcher(testScheduler)
|
||||
val handle = bind(worker, dispatcher)
|
||||
|
||||
Reference in New Issue
Block a user