ktonon/elm-test-extra/1.5.1

NOTE: this package is not compatible with Elm 0.19.1

Test.Extra

Extends Test with specialized test and describe function.

Describing JSON Decoders

Write concise test for JSON decoders

= FailsToDecode
| FailsToDecodeWith String
| DecodesTo a

Expectation for a decoder result.

  • FailsToDecode - expect the decoder to fail, the failure message can be anything
  • FailsToDecodeWith String - expect the decoder to fail with a specific message
  • DecodesTo a - expect the decoder to succeed, decoding to the provided value
describeDecoder : String -> Decoder a -> List ( String, DecoderExpectation a ) -> Test

Exercise a decoder over a list of input/expectation pairs.

For example

describeDecoder "int"
  Json.Decode.int
  [ ( "", FailsToDecode )
  , ( "foo", FailsToDecode )
  , ( "1", DecodesTo 1 )
  , ( "1.5", FailsToDecode )
  ]
testDecoder : Decoder a -> ( String, DecoderExpectation a ) -> Test

Exercise a decoder with a JSON encoded string.

For example

testDecoder Json.Decode.string
  "\"foo\""
  (DecodesTo "foo")