Elmish.Test
- Package
- purescript-elmish
- Repository
- collegevine/purescript-elmish
#runUI Source
runUI :: forall state message m. Monad m => (state -> message -> Transition m message state) -> Transition m message state -> TestMachine m message state Unit -> m Unit
A test harness for UI state machines.
This function takes an "update" function, initial state, and a list of messages that are to be fed into the state machine, expressed as a series of monadic operations. It then runs the state machine through those messages, taking detours to process any new messages that the machine itself produces (if any).
Example:
import MyComponent as C
import Elmish.Test as T
T.runUI C.update C.initialState do
T.message C.Next
T.assert \s -> equal s.pageIndex 1
T.message C.Next
T.assert \s -> equal s.pageIndex 2
T.message C.Back
T.assert \s -> equal s.pageIndex 1
#message Source
message :: forall state message m. Monad m => message -> TestMachine m message state Unit
Feeds a message into the component being tested. If the component produces
any commands as a result of the update, runs through those commands as
well. See example on runUI
.
#assert Source
assert :: forall state message m. Monad m => (state -> m Unit) -> TestMachine m message state Unit
Validates current state of the component under test with the provided
validation function. The function is expected to produce side effects as it
sees fit according to the result of validation. For example, it might call
one of the Test.Spec assertion functions. See example on runUI
.
#getState Source
getState :: forall state message m. Monad m => TestMachine m message state state
Returns the current state of the component under test.