chapter 6: Add unit-tests

This commit is contained in:
Alexander Kobjolke 2023-12-16 14:42:57 +01:00
parent 43971bd268
commit 034b147740
3 changed files with 23 additions and 2 deletions

View file

@ -23,7 +23,9 @@
} }
}, },
"test-dependencies": { "test-dependencies": {
"direct": {}, "direct": {
"elm-explorations/test": "2.1.2"
},
"indirect": {} "indirect": {}
} }
} }

View file

@ -1,4 +1,4 @@
port module PhotoGroove exposing (main) port module PhotoGroove exposing (main, photoDecoder)
import Browser import Browser
import Html exposing (Attribute, Html, button, canvas, div, h1, h3, img, input, label, node, text) import Html exposing (Attribute, Html, button, canvas, div, h1, h3, img, input, label, node, text)

19
tests/PhotoGrooveTest.elm Normal file
View file

@ -0,0 +1,19 @@
module PhotoGrooveTest exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Json.Decode as J
import PhotoGroove as Testee
import Test exposing (..)
suite : Test
suite =
describe "photoDecoder"
[ test "title defaults to '(untitled)'" <|
\_ ->
"""{"url": "example.com", "size": 5}"""
|> J.decodeString Testee.photoDecoder
|> Result.map (\p -> p.title)
|> Expect.equal (Ok "(untitled)")
]