dillonkearns/elm-pages/12.2.0

NOTE: the latest version is 12.3.0

Test.PagesProgram.SimulatedSub

Simulated subscriptions for testing. These parallel Elm's Sub type but are inspectable by the test framework.

Use these with PagesProgram.withSimulatedSubscriptions to register subscriptions, then send data through them with PagesProgram.simulateIncomingPort.

import Test.PagesProgram.SimulatedSub as SimulatedSub


-- In your test setup:
|> PagesProgram.withSimulatedSubscriptions
    (\model ->
        if model.isConnected then
            SimulatedSub.port_ "websocketData"
                (Decode.string |> Decode.map GotMessage)
        else
            SimulatedSub.none
    )
type SimulatedSub msg
= NoneSub
| BatchSub (List (SimulatedSub msg))
| PortSub String (Decoder msg)

A simulated subscription that the test framework can inspect and trigger.

No subscription. Parallels Sub.none.

batch : List (SimulatedSub msg) -> SimulatedSub msg

Combine multiple subscriptions. Parallels Sub.batch.

port_ : String -> Decoder msg -> SimulatedSub msg

Subscribe to an incoming port. Provide the port name and a decoder that produces your message type.

SimulatedSub.port_ "websocketData"
    (Decode.string |> Decode.map GotMessage)
map : (a -> msg) -> SimulatedSub a -> SimulatedSub msg

Transform the messages produced by a subscription.