Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module WebSocketTests exposing (..)
import Test exposing (..)
import Expect
import Elmer exposing (atIndex, (<&&>))
import Elmer.Html as Markup
import Elmer.Html.Matchers exposing (elements, hasText)
import Elmer.Spy as Spy exposing (Spy, andCallFake)
import Elmer.Platform.Subscription as Subscription
import WebSocket
import App
webSocketListenSpy : Spy
webSocketListenSpy =
Spy.create "webSocketListen" (\_ -> WebSocket.listen)
|> andCallFake (\_ tagger ->
Subscription.fake "webSocket" tagger
)
listenTests : Test
listenTests =
describe "listen for message"
[ describe "when a list of items is received via the websocket"
[ test "it shows the items" <|
\() ->
Elmer.given App.defaultModel App.view App.update
|> Spy.use [ webSocketListenSpy ]
|> Subscription.with (\() -> App.subscriptions)
|> Subscription.send "webSocket" "[\"fun\",\"sun\",\"beach\"]"
|> Markup.target "#items li"
|> Markup.expect (elements <|
(atIndex 0 <| hasText "fun") <&&>
(atIndex 1 <| hasText "sun") <&&>
(atIndex 2 <| hasText "beach")
)
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment