diff --git a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt index ec7aeda..6feed8a 100644 --- a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt +++ b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt @@ -70,6 +70,20 @@ private constructor( Prism.id(), testDispatcher ) + fun , Environment> create ( + state: State, + reducer: Reducer, + environment: Environment, + testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() + ) = + TestStore( + state, + reducer, + environment, + Lens.id(), + Prism.id(), + testDispatcher + ) } fun scope( @@ -84,7 +98,9 @@ private constructor( fromLocalAction, testDispatcher ) - + + @kotlin.ExperimentalStdlibApi + @OptIn(kotlin.ExperimentalStdlibApi::class) fun assert(block: AssertionBuilder.() -> Unit) { val assertion = AssertionBuilder { toLocalState.get(state) @@ -112,19 +128,25 @@ private constructor( when (step) { is Step.Send -> { - require(receivedActions.isEmpty()) { "Must handle all actions" } + require(receivedActions.isEmpty()) { "Must handle all actions. Unhandled actions:\n" + receivedActions.joinToString(separator = "\n") } runReducer(fromLocalAction.reverseGet(step.action)) expectedState = step.block(expectedState) } is Step.Receive -> { - require(receivedActions.isNotEmpty()) { "Expected to receive an action, but received none" } + require(receivedActions.isNotEmpty()) { + "Expected to receive" + receivedActions.joinToString(separator = "\n") + "but received none" + } val receivedAction = receivedActions.removeFirst() - require(step.action == receivedAction) { "Actual and expected actions do not match" } + require(step.action == receivedAction) { + "Actual and expected states do not match.\n\n${step.action}\n---vs---\n$receivedAction" + } runReducer(fromLocalAction.reverseGet(step.action)) expectedState = step.block(expectedState) } is Step.Environment -> { - require(receivedActions.isEmpty()) { "Must handle all received actions before performing this work" } + require(receivedActions.isEmpty()) { + "Must handle all received actions before performing this work." + receivedActions.joinToString(separator = "\n") + "are not handled" + } step.block(environment) } is Step.Do -> step.block() @@ -132,13 +154,11 @@ private constructor( val actualState = toLocalState.get(state) require(actualState == expectedState) { - println(actualState) - println("---vs---") - println(expectedState) - "Actual and expected states do not match" + "Actual and expected states do not match\n\n$actualState\n---vs---\n$expectedState" } } - require(receivedActions.isEmpty()) { "Must handle all actions" } + require(receivedActions.isEmpty()) { "Must handle all actions. Unhandled actions:\n" + receivedActions.joinToString(separator = "\n") } } } +