diff --git a/README.md b/README.md index 056eb2015..e5ba0562f 100644 --- a/README.md +++ b/README.md @@ -1277,6 +1277,7 @@ So this is similar to the `returnsMany` semantics. |`coAndThen { code }`|specify that the matched call answers with a coroutine code block with `answer scope`| |`andThenAnswer answerObj`|specify that the matched call answers with an Answer object| |`andThen { nothing }`|specify that the matched call answers null| +|`andThenJust Runs`|specify that the matched call is returning Unit (available since v1.12.2)| ### Answer scope diff --git a/dsl/common/src/main/kotlin/io/mockk/API.kt b/dsl/common/src/main/kotlin/io/mockk/API.kt index a964d957c..d50a88f12 100644 --- a/dsl/common/src/main/kotlin/io/mockk/API.kt +++ b/dsl/common/src/main/kotlin/io/mockk/API.kt @@ -6,6 +6,7 @@ import io.mockk.InternalPlatformDsl.toStr import io.mockk.MockKGateway.* import kotlin.coroutines.Continuation import kotlin.reflect.KClass +import io.mockk.* /** * Exception thrown by library @@ -2160,6 +2161,12 @@ class MockKAdditionalAnswerScope( andThenAnswer(CoFunctionAnswer { MockKAnswerScope(lambda, it).answer(it) }) } +/** + * Part of DSL. Answer placeholder for Unit returning functions. + */ +@Suppress("UNUSED_PARAMETER") +infix fun MockKAdditionalAnswerScope.andThenJust(runs: Runs) = andThenAnswer(ConstantAnswer(Unit)) + internal fun List.allConst() = this.map { ConstantAnswer(it) }