Skip to content

Instantly share code, notes, and snippets.

@brian-watkins
Created June 11, 2017 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brian-watkins/cd243ba71dc29d94973d60f13cc3780d to your computer and use it in GitHub Desktop.
Save brian-watkins/cd243ba71dc29d94973d60f13cc3780d to your computer and use it in GitHub Desktop.
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