All Projects → avh4 → elm-testable

avh4 / elm-testable

Licence: other
Makes Cmds and Tasks testable

Programming Languages

elm
856 projects
shell
77523 projects

Projects that are alternatives of or similar to elm-testable

Azure-AppServices-Diagnostics
Azure App Service Diagnostics provides developers ability to write various diagnostics features which helps customers to diagnose and troubleshoot their applications hosted on app services.
Stars: ✭ 42 (+0%)
Mutual labels:  deprecated
VRTK.Tutorials.OculusIntegration
Prefabs and code for use with the Oculus Integration Unity Package
Stars: ✭ 26 (-38.1%)
Mutual labels:  deprecated
margarine
Butter Cloudiness by Example
Stars: ✭ 15 (-64.29%)
Mutual labels:  deprecated
pages
DEPRECATED: Publishing platform for 18F sites a la GitHub pages
Stars: ✭ 63 (+50%)
Mutual labels:  deprecated
prestans
A WSGI compliant REST micro-framework.
Stars: ✭ 14 (-66.67%)
Mutual labels:  deprecated
atom-perfectionist
Beautify CSS and SCSS
Stars: ✭ 19 (-54.76%)
Mutual labels:  deprecated
passion
An object-oriented LÖVE game engine
Stars: ✭ 35 (-16.67%)
Mutual labels:  deprecated
marquez-airflow
Airflow support for Marquez
Stars: ✭ 33 (-21.43%)
Mutual labels:  deprecated
SAM-BAR
SAM Boot Assistant Reloaded - Combo USB CDC+MSD Bootloader for Atmel/Microchip SAMD21 microcontroller
Stars: ✭ 29 (-30.95%)
Mutual labels:  deprecated
arduino-client
[deprecated] [Arduino (compatible)] Arduino c++ client library to connect to the AllThingsTalk platform
Stars: ✭ 19 (-54.76%)
Mutual labels:  deprecated
atom-fixmyjs
[DEPRECATED] Automagically fix JSHint lint warnings
Stars: ✭ 88 (+109.52%)
Mutual labels:  deprecated
wallet-lib
DEPRECATED A pure and extensible JavaScript Wallet Library for Dash
Stars: ✭ 13 (-69.05%)
Mutual labels:  deprecated
class-name-builder
A small, chainable, immutable utility for building up class name strings in application logic
Stars: ✭ 46 (+9.52%)
Mutual labels:  deprecated
capybara-json
No description or website provided.
Stars: ✭ 61 (+45.24%)
Mutual labels:  deprecated
io
A Node.js based system for managing a stream, including a chat bot, overlays, stream note generation and more.
Stars: ✭ 22 (-47.62%)
Mutual labels:  deprecated
dashboard-extension-simple-table
⛔ DEPRECATED. This project was moved to a new repository. Visit https://github.com/DevExpress/dashboard-extensions to find an updated version.
Stars: ✭ 37 (-11.9%)
Mutual labels:  deprecated
sassquatch
CSS foundation & framework for Meetup
Stars: ✭ 25 (-40.48%)
Mutual labels:  deprecated
fullcontact4j
⛔ [DEPRECATED] A Java client for the FullContact API
Stars: ✭ 28 (-33.33%)
Mutual labels:  deprecated
mono-reactive
open source Reactive Extensions (Rx) implementation for Mono
Stars: ✭ 65 (+54.76%)
Mutual labels:  deprecated
QR
DEPRECATED The bookmarklet and extensions generate QRCode of the current URL for viewing on mobile devices (Google Chrome/Mozilla Firefox/Opera/Safari)
Stars: ✭ 20 (-52.38%)
Mutual labels:  deprecated

Deprecated

Now use avh4/elm-program-test instead. (elm-testable only works with ELm 0.17)

Note:

elm-testable does not support Elm 0.18. A new package is currently in development that will allow testing of Cmds, Tasks, and Subs without the need for elm-testable's wrappers. More details will be posted to elm-discuss when it is available. (See the rewrite-native branch.)

Build Status

avh4/elm-testable

This package allows you to write components that follow the Elm Architecture in a way that is testable. To allow this, elm-testable provides testable versions of the Task, Effects, and Http modules, as well as Testable.TestContext to test testable components and Testable to integrate testable components with your Elm app.

Example testable component

The only difference between a testable component and a standard component is the added Testable. in several imports. (With the exception of Cmd, which conflicts with the default import of Platform.Cmd in Elm 0.17.)

Here is the diff of converting RandomGif.elm into a testable component:

diff --git b/examples/RandomGif.elm a/examples/RandomGif.elm
@@ -6,8 +6,9 @@ import Html exposing (..)
 import Json.Decode as Json
-import Http
-import Task
+import Testable.Cmd
+import Testable.Http as Http
+import Testable.Task as Task
 
 @ -20,7 +21,7 @@ type alias Model =

-init : String -> String -> ( Model, Cmd Msg )
+init : String -> String -> ( Model, Testable.Cmd.Cmd Msg )
 init apiKey topic =
@@ -36,7 +37,7 @@ type Msg
 
-update : Msg -> Model -> ( Model, Cmd Msg )
+update : Msg -> Model -> ( Model, Testable.Cmd.Cmd Msg )
 update msg model =
@@ -44,7 +45,7 @@ update msg model =
             ( Model model.apiKey model.topic (Maybe.withDefault model.gifUrl maybeUrl)
-            , Cmd.none
+            , Testable.Cmd.none
             )
@@ -89,7 +90,7 @@ imgStyle url =
 
-getRandomGif : String -> String -> Cmd Msg
+getRandomGif : String -> String -> Testable.Cmd.Cmd Msg
 getRandomGif apiKey topic =
     Http.get decodeUrl (randomUrl apiKey topic)
         |> Task.perform (always Nothing >> NewGif)
diff --git b/examples/Main.elm a/examples/Main.elm
@@ -3,12 +3,13 @@ module Main exposing (..)
 import Task
+import Testable
 
 main =
     Html.App.program
-        { init = init "__API_KEY__" "funny cats"
-        , update = update
+        { init = Testable.init <| init "__API_KEY__" "funny cats"
+        , update = Testable.update update
         , view = view

Example tests

Here is an example of the types of tests you can write for testable components:

import ElmTest exposing (..)
import Testable.TestContext exposing (..)
import Testable.Effects as Effects
import Testable.Http as Http


myComponent =
    { init = MyComponent.init
    , update = MyComponent.update
    }


all : Test
all =
    suite "MyComponent"
        [ myComponent
            |> startForTest
            |> currentModel
            |> assertEqual (Ok expectedModelValue)
            |> test "sets initial state"
        , myComponent
            |> startForTest
            |> assertHttpRequest (Http.getRequest "https://example.com/myResource")
            |> test "makes initial HTTP request"
        , myComponent
            |> startForTest
            |> resolveHttpRequest (Http.getRequest "https://example.com/myResource")
                (Http.ok """{"data":"example JSON response"}""")
            |> assertEqual (Ok expectedModelValue)
            |> test "updated the model on HTTP success"
        , myComponent
            |> startForTest
            |> update (MyComponent.LoadDetails 1234)
            |> assertHttpRequest (Http.getRequest "https://example.com/myResource/1234")
            |> test "pressing the button makes a new HTTP request"
        ]

Here are complete tests for the RandomGif example.

Example integration with Main

To convert your testable view and update functions into functions that work with StartApp, use the Testable module:

main : Program Never
main =
    Html.App.program
        { init = Testable.init MyComponent.init
        , update = Testable.update MyComponent.update
        , view = MyComponent.view
        , subscriptions = MyComponent.subscriptions
        }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].