chapter 6: Replace unit by property test
This commit is contained in:
parent
034b147740
commit
5e735e1b62
1 changed files with 12 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ module PhotoGrooveTest exposing (..)
|
|||
import Expect exposing (Expectation)
|
||||
import Fuzz exposing (Fuzzer, int, list, string)
|
||||
import Json.Decode as J
|
||||
import Json.Encode as Encode exposing (Value)
|
||||
import PhotoGroove as Testee
|
||||
import Test exposing (..)
|
||||
|
||||
|
|
@ -10,10 +11,16 @@ 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)
|
||||
[ fuzz2 Fuzz.string Fuzz.int "title always defaults to '(untitled)'" <|
|
||||
\url size ->
|
||||
mkPhoto url size
|
||||
|> J.decodeValue Testee.photoDecoder
|
||||
|> Result.map .title
|
||||
|> Expect.equal (Ok "(untitled)")
|
||||
]
|
||||
|
||||
|
||||
mkPhoto : String -> Int -> Value
|
||||
mkPhoto url size =
|
||||
[ ( "url", Encode.string url ), ( "size", Encode.int size ) ]
|
||||
|> Encode.object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue