com.jeppeman.mockposable.mockk.MockposableMockK.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockposable-runtime-mockk Show documentation
Show all versions of mockposable-runtime-mockk Show documentation
A tool that enables stubbing and verification of @Composable-annotated functions
The newest version!
package com.jeppeman.mockposable.mockk
import androidx.compose.runtime.Composable
import com.jeppeman.mockposable.runComposableOneShot
import io.mockk.*
/**
* @see [every]
*/
fun everyComposable(
stubBlock: @Composable MockKMatcherScope.() -> T
): MockKStubScope = MockK.useImpl {
MockKDsl.internalEvery { runComposableOneShot { stubBlock() } }
}
/**
* @see [MockKStubScope.answers]
*/
infix fun MockKStubScope.answersComposable(
answer: @Composable MockKAnswerScope.(Call) -> T
): MockKAdditionalAnswerScope = answers { call ->
runComposableOneShot(true) { answer(call) }
}
/**
* @see [MockKAdditionalAnswerScope.andThenAnswer]
*/
infix fun MockKAdditionalAnswerScope.andThenComposable(
answer: @Composable MockKAnswerScope.(Call) -> T
): MockKAdditionalAnswerScope = andThenAnswer { call ->
runComposableOneShot(true) { answer(call) }
}
/**
* @see [verify]
*/
fun verifyComposable(
ordering: Ordering = Ordering.UNORDERED,
inverse: Boolean = false,
atLeast: Int = 1,
atMost: Int = Int.MAX_VALUE,
exactly: Int = -1,
timeout: Long = 0,
verifyBlock: @Composable MockKVerificationScope.() -> Unit
) = MockK.useImpl {
MockKDsl.internalVerify(
ordering = ordering,
inverse = inverse,
atLeast = atLeast,
atMost = atMost,
exactly = exactly,
timeout = timeout,
verifyBlock = { runComposableOneShot { verifyBlock() } }
)
}
/**
* @see [verifyAll]
*/
fun verifyComposableAll(
inverse: Boolean = false,
verifyBlock: @Composable MockKVerificationScope.() -> Unit
) = MockK.useImpl {
MockKDsl.internalVerifyAll(
inverse = inverse,
verifyBlock = { runComposableOneShot { verifyBlock() } }
)
}
/**
* @see [verifyOrder]
*/
fun verifyComposableOrder(
inverse: Boolean = false,
verifyBlock: @Composable MockKVerificationScope.() -> Unit
) = MockK.useImpl {
MockKDsl.internalVerifyOrder(
inverse = inverse,
verifyBlock = { runComposableOneShot { verifyBlock() } }
)
}
/**
* @see [verifySequence]
*/
fun verifyComposableSequence(
inverse: Boolean = false,
verifyBlock: @Composable MockKVerificationScope.() -> Unit
) = MockK.useImpl {
MockKDsl.internalVerifySequence(
inverse = inverse,
verifyBlock = { runComposableOneShot { verifyBlock() } }
)
}