Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add andThenJust #759

Merged
merged 3 commits into from Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions dsl/common/src/main/kotlin/io/mockk/API.kt
Expand Up @@ -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
Expand Down Expand Up @@ -2160,6 +2161,12 @@ class MockKAdditionalAnswerScope<T, B>(
andThenAnswer(CoFunctionAnswer { MockKAnswerScope<T, B>(lambda, it).answer(it) })
}

/**
* Part of DSL. Answer placeholder for Unit returning functions.
*/
@Suppress("UNUSED_PARAMETER")
infix fun MockKAdditionalAnswerScope<Unit, Unit>.andThenJust(runs: Runs) = andThenAnswer(ConstantAnswer(Unit))


internal fun <T> List<T>.allConst() = this.map { ConstantAnswer(it) }

Expand Down