Logo

0x3d.Site

is designed for aggregating information.
Welcome
check repository here

elm-spec

Use elm-spec to write specs that describe the behavior of your Elm program.

You think TDD/BDD is great, and maybe you're already writing tests in Elm or using tools like Cypress to test your program end-to-end. Why use elm-spec?

  • elm-spec allows you to describe behaviors that involve HTML, browser navigation, HTTP, Time, ports, commands, and subscriptions -- and there's no need to structure your code in any special way to do so (although you can if you wish).
  • elm-spec does not simulate calls to your program's view or update functions, and it lets the Elm runtime handle commands and subscriptions; your program interacts with the Elm runtime just as it would in production.
  • elm-spec exercises your program in a DOM environment (JSDOM or a web browser).
  • elm-spec allows you to write specs that describe the behavior of parts of your program in isolation from others. This makes those specs easier to write and easier to understand.

In short, with elm-spec you get the confidence you would from a browser-based end-to-end testing tool like Cypress, without losing the convenience of elm-based testing tools. You can still write your specs in Elm and you can still test parts of your code in isolation, but your specs run in a browser and they exercise your code just like it will be exercised in production.

Getting Started

  1. Create a directory called specs for your specs and change into that directory.

  2. Initialize a new elm app with elm init. Add your program's source directory to the source-directories field of elm.json.

  3. Install elm-spec: elm install brian-watkins/elm-spec.

  4. Install any other dependencies your app needs.

  5. Add a file called Runner.elm to your specs src directory. It should look something like this:

port module Runner exposing
  ( program
  , browserProgram
  , skip
  , pick
  )

import Spec exposing (Message)

port elmSpecOut : Message -> Cmd msg
port elmSpecIn : (Message -> msg) -> Sub msg
port elmSpecPick : () -> Cmd msg

config : Spec.Config msg
config =
  { send = elmSpecOut
  , listen = elmSpecIn
  }

pick =
  Spec.pick elmSpecPick

skip =
  Spec.skip

program =
  Spec.program config

browserProgram =
  Spec.browserProgram config

You must create the elmSpecOut and elmSpecIn ports and provide them to Spec.program or Spec.browserProgram via a Spec.Config value.

You must also create the elmSpecPick port and provide it to Spec.pick.

Now you can write spec modules. Each spec module is an elm program and so must have a main function. To construct the main function, just reference program or browserProgram from your Runner.elm and provide a List Spec to run.

During the course of development, it's often useful to run only certain scenarios. In that case, use pick from your Runner.elm to designate those scenarios. See the docs for Spec.pick for more information.

You can also skip scenarios, if you like, by using Spec.skip.

Here's an example spec module:

module SampleSpec exposing (main)

import Spec exposing (..)
import Spec.Setup as Setup
import Spec.Markup as Markup
import Spec.Markup.Selector exposing (..)
import Spec.Markup.Event as Event
import Spec.Claim as Claim
import Runner
import Main as App


clickSpec : Spec App.Model App.Msg
clickSpec =
  describe "an html program"
  [ scenario "a click event" (
      given (
        Setup.initWithModel App.defaultModel
          |> Setup.withUpdate App.update
          |> Setup.withView App.view
      )
      |> when "the button is clicked three times"
        [ Markup.target << by [ id "my-button" ]
        , Event.click
        , Event.click
        , Event.click
        ]
      |> it "renders the count" (
        Markup.observeElement
          |> Markup.query << by [ id "count-results" ]
          |> expect (
            Claim.isSomethingWhere <|
            Markup.text <|
            Claim.isStringContaining 1 "You clicked the button 3 time(s)"
          )
      )
    )
  ]

main =
  Runner.browserProgram
    [ clickSpec
    ]

Running Specs

To run your specs, you need to install a runner. There are currently two options.

elm-spec-runner

You can run your specs in JSDOM or a real browser, right from the command line.

$ npm install --save-dev elm-spec-runner

Then, assuming your specs are in a directory called ./specs, just run your spec suite like so:

$ npx elm-spec

By default, elm-spec-runner will execute your specs in a JSDOM environment. You can configure elm-spec-runner to execute your specs in a real browser via a command line option; chromium, webkit, and firefox are all available.

See elm-spec-runner for more details on command line options.

karma-elm-spec-framework

You can also run your specs in a real browser via Karma.

See karma-elm-spec-framework for more details.

More Examples

For more examples, see the docs for elm-spec. In particular, there are examples demonstrating how to describe behavior related to HTTP requests, describe behavior related to ports, observe navigation changes, control time during a spec, select and work with files and downloads, and use witnesses to ensure one part of a program acts in an expected way.

For even more examples, see the specs for elm-spec.

For a real-world test suite, see the specs for a simple code-guessing game.

Extra

I suggest adding one more file to your spec suite: Spec/Extra.elm.

module Spec.Extra exposing (equals)

import Spec.Claim as Claim exposing (Claim)

equals : a -> Claim a
equals =
  Claim.isEqual Debug.toString

Then, you can import the equals function from this module without having to write out Claim.isEqual Debug.toString every time.

Elm
Elm
Elm is a functional programming language designed for building front-end web applications. It emphasizes simplicity, performance, and reliability, producing no runtime errors. Elm is ideal for creating robust user interfaces.
compiler/hints at master · elm/compiler
compiler/hints at master · elm/compiler
GitHub - rogeriochaves/spades: Start an Elm SPA ready to the real world
GitHub - rogeriochaves/spades: Start an Elm SPA ready to the real world
GitHub - huytd/kanelm: Kanban board built with Elm
GitHub - huytd/kanelm: Kanban board built with Elm
GitHub - lydell/elm-watch: `elm make` in watch mode. Fast and reliable.
GitHub - lydell/elm-watch: `elm make` in watch mode. Fast and reliable.
GitHub - stereobooster/type-o-rama: 👾 JS type systems interportability
GitHub - stereobooster/type-o-rama: 👾 JS type systems interportability
GitHub - tarbh-engineering/journal: The secure, private journal.
GitHub - tarbh-engineering/journal: The secure, private journal.
GitHub - ashellwig/generator-elm-mdl: Yeoman generator for elm-mdl in pure elm
GitHub - ashellwig/generator-elm-mdl: Yeoman generator for elm-mdl in pure elm
GitHub - elmariofredo/elm-hn-pwa: Hacker News as a PWA built with Elm
GitHub - elmariofredo/elm-hn-pwa: Hacker News as a PWA built with Elm
GitHub - simonewebdesign/elm-new: 💾 Generate a new Elm project from the command line (Elm 0.16+)
GitHub - simonewebdesign/elm-new: 💾 Generate a new Elm project from the command line (Elm 0.16+)
GitHub - stil4m/elm-analyse: A tool that allows you to analyse your Elm code, identify deficiencies and apply best practices.
GitHub - stil4m/elm-analyse: A tool that allows you to analyse your Elm code, identify deficiencies and apply best practices.
GitHub - pzp1997/elm-ios: Bringing the wonders of Elm to the iOS platform
GitHub - pzp1997/elm-ios: Bringing the wonders of Elm to the iOS platform
GitHub - agrafix/elm-bridge: Haskell: Derive Elm types from Haskell types
GitHub - agrafix/elm-bridge: Haskell: Derive Elm types from Haskell types
articles/switching_from_imperative_to_functional_programming_with_games_in_Elm.md at master · Dobiasd/articles
articles/switching_from_imperative_to_functional_programming_with_games_in_Elm.md at master · Dobiasd/articles
GitHub - evancz/elm-todomvc: The TodoMVC app written in Elm, nice example for beginners.
GitHub - evancz/elm-todomvc: The TodoMVC app written in Elm, nice example for beginners.
GitHub - jschomay/elm-narrative-engine: A tool for building interactive fiction style stories in Elm.
GitHub - jschomay/elm-narrative-engine: A tool for building interactive fiction style stories in Elm.
GitHub - rtfeldman/grunt-elm: Grunt plugin that compiles Elm files to JavaScript.
GitHub - rtfeldman/grunt-elm: Grunt plugin that compiles Elm files to JavaScript.
GitHub - jfairbank/run-elm: Run Elm code from the command line
GitHub - jfairbank/run-elm: Run Elm code from the command line
GitHub - JustusAdam/elm-init: Initialise scaffolding for a new Elm project
GitHub - JustusAdam/elm-init: Initialise scaffolding for a new Elm project
GitHub - halfzebra/create-elm-app: 🍃 Create Elm apps with zero configuration
GitHub - halfzebra/create-elm-app: 🍃 Create Elm apps with zero configuration
GitHub - halfzebra/elm-examples: :book: Practical examples in Elm
GitHub - halfzebra/elm-examples: :book: Practical examples in Elm
GitHub - khusnetdinov/elmkit: :school_satchel: Elm kit is web application boilerplate kit for development. This kit build on Brunch, Node, Sass, Elm-lang. It helps you to start development more productive following best practices.
GitHub - khusnetdinov/elmkit: :school_satchel: Elm kit is web application boilerplate kit for development. This kit build on Brunch, Node, Sass, Elm-lang. It helps you to start development more productive following best practices.
GitHub - rofrol/elm-games: All Elm Games (hopefully)
GitHub - rofrol/elm-games: All Elm Games (hopefully)
GitHub - Chadtech/elmish-wasm: Experiment to compile something Elm-ish to Wasm
GitHub - Chadtech/elmish-wasm: Experiment to compile something Elm-ish to Wasm
GitHub - robertjlooby/elm-koans: A set of koans for learning Elm
GitHub - robertjlooby/elm-koans: A set of koans for learning Elm
Rework Vim install instructions · Issue #610 · avh4/elm-format
Rework Vim install instructions · Issue #610 · avh4/elm-format
GitHub - evancz/elm-architecture-tutorial: How to create modular Elm code that scales nicely with your app
GitHub - evancz/elm-architecture-tutorial: How to create modular Elm code that scales nicely with your app
GitHub - brian-watkins/elm-spec: Describe the behavior of Elm programs
GitHub - brian-watkins/elm-spec: Describe the behavior of Elm programs
GitHub - zwilias/elm-json: Install, upgrade and uninstall Elm dependencies
GitHub - zwilias/elm-json: Install, upgrade and uninstall Elm dependencies
GitHub - gicentre/litvis: Literate Visualization: Theory, software and examples
GitHub - gicentre/litvis: Literate Visualization: Theory, software and examples
GitHub - eeue56/elm-for-web-developers: A collection of tips for people using Elm from a web-dev background
GitHub - eeue56/elm-for-web-developers: A collection of tips for people using Elm from a web-dev background
Elm
More on Elm

Programming Tips & Tricks

Code smarter, not harder—insider tips and tricks for developers.

Error Solutions

Turn frustration into progress—fix errors faster than ever.

Shortcuts

The art of speed—shortcuts to supercharge your workflow.
  1. Collections 😎
  2. Frequently Asked Question's 🤯

Tools

available to use.

Made with ❤️

to provide resources in various ares.