I’m trying to trigger an “ArrowUp” event from elm-spec in a spec test.
Using an example from the spec tests for elm-spec, I found this helper function:
keyPressEvent : String -> Step.Context model -> Step.Command msg keyPressEvent char = Encode.object [ ( "key", Encode.string char ) ] |> Event.trigger "keypress"
Making this a bit more verbose I get
upArrowPressed = Json.Encode.object [ ( "key", Json.Encode.string "ArrowUp") ] |> Event.trigger "keypress"
In the spec test I’m using it like:
... Spec.when "ArrowUp is pressed" [ Markup.target << document , upArrowPressed ] ...
In Main I’m subscribing to these events with
subscriptions model = Sub.batch [ ... , onKeyDown (Decode.succeed ArrowUp) ]
I have tried changing “key” to “keyCode” and encoding the int code (38), “Keypress” to “keydown”. Also tried running the tests in the browser rather than JSDOM to no avail. Could I get a point in the right direction?