Extends Test
with specialized test and describe function.
Write concise test for JSON decoders
Expectation for a decoder result.
FailsToDecode
- expect the decoder to fail, the failure message can be anythingFailsToDecodeWith String
- expect the decoder to fail with a specific messageDecodesTo a
- expect the decoder to succeed, decoding to the provided valuedescribeDecoder : String -> Json.Decode.Decoder a -> (a -> String) -> List ( String, DecoderExpectation a ) -> Test
Exercise a decoder over a list of input/expectation pairs.
For example
describeDecoder "int"
Json.Decode.int
Debug.toString
[ ( "", FailsToDecode )
, ( "foo", FailsToDecode )
, ( "1", DecodesTo 1 )
, ( "1.5", FailsToDecode )
]
testDecoder : Json.Decode.Decoder a -> (a -> String) -> ( String, DecoderExpectation a ) -> Test
Exercise a decoder with a JSON encoded string.
For example
testDecoder Json.Decode.string
Debug.toString
( "\"foo\"", DecodesTo "foo" )