Skip to content

Instantly share code, notes, and snippets.

@brian-watkins
Created April 15, 2018 17:05
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/55ac2f396bc5a9ea67aff2f120a4b01d to your computer and use it in GitHub Desktop.
Save brian-watkins/55ac2f396bc5a9ea67aff2f120a4b01d to your computer and use it in GitHub Desktop.
persistScoresTests : Test
persistScoresTests =
describe "when a score is persisted" <|
let
testState =
Headless.givenCommand (\_ -> LocalStoragePersistScore.execute <| 217)
|> Spy.use [ saveScoreSpy, getScoresSpy ]
|> Subscription.with (\() -> (\_ -> LocalStoragePersistScore.subscriptions ScoreTagger))
|> Subscription.send "scores-sub" [ 190, 217, 218, 332 ]
in
[ test "it requests the scores" <|
\() ->
testState
|> Spy.expect "save-score-spy" (
wasCalledWith [ intArg 217 ]
)
, test "it sends the recorded scores" <|
\() ->
testState
|> Headless.expectMessages (exactly 1 <|
Expect.equal (ScoreTagger [ 190, 217, 218, 332 ])
)
]
type TestMsg
= ScoreTagger (List Score)
saveScoreSpy : Spy
saveScoreSpy =
Spy.create "save-score-spy" (\_ -> ScoreStore.saveScore)
|> andCallFake (\_ ->
Cmd.none
)
getScoresSpy : Spy
getScoresSpy =
Spy.create "scores-spy" (\_ -> ScoreStore.scores)
|> andCallFake (\tagger ->
Subscription.fake "scores-sub" tagger
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment