Skip to content

Instantly share code, notes, and snippets.

@lenards
Created April 20, 2019 04:00
Show Gist options
  • Save lenards/ef0599b201324cca43b5b1540c70e646 to your computer and use it in GitHub Desktop.
Save lenards/ef0599b201324cca43b5b1540c70e646 to your computer and use it in GitHub Desktop.
If you place `Example.elm` under a "tests" directory, then `npm run test` should correctly execute `elm-test`
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"NoRedInk/elm-json-decode-pipeline": "1.0.0",
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm-explorations/test": "1.2.1"
},
"indirect": {
"elm/random": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
module Example exposing (Event, decoderSuite, eventDecoder)
import Expect exposing (Expectation)
import Json.Decode as Json exposing (Decoder)
import Json.Decode.Pipeline exposing (optional, required)
import Test exposing (..)
type alias Event =
{ date : String
, event : String
, venue : String
, address : String
, act : String
, genre : String
, id : Int
}
eventDecoder : Decoder Event
eventDecoder =
Json.succeed Event
|> required "date" Json.string
|> required "event" Json.string
|> required "venue" Json.string
|> required "address" Json.string
|> required "act" Json.string
|> required "genre" Json.string
|> required "id" Json.int
decoderSuite : Test
decoderSuite =
describe "The Api Decoding Module, any Decoders defined within the application"
[ describe "decoder for Event"
[ test "basic event decoded" <|
\() ->
"""
{
"id": 38000002,
"act" : "first",
"event" : "Good Friday at Jackie Treehorn's",
"venue" : "Malibu Estate",
"address" : "10104 Angelo View Drive, Beverly Hills, CA",
"date" : "2019-04-19",
"genre" : "Adult"
}
"""
|> Json.decodeString eventDecoder
|> Expect.equal
(Ok
(Event
"2019-04-19"
"Good Friday at Jackie Treehorn's"
"Malibu Estate"
"10104 Angelo View Drive, Beverly Hills, CA"
"first"
"Adult"
38000002
)
)
]
]
{
"name": "elm-json-unit-test",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "elm-test"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"elm": "^0.19.0-bugfix6",
"elm-test": "^0.19.0-rev6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment