{"id":15211115,"url":"https://github.com/avh4/elm-program-test","last_synced_at":"2025-08-20T10:31:24.134Z","repository":{"id":30860151,"uuid":"126131978","full_name":"avh4/elm-program-test","owner":"avh4","description":"Test Elm programs","archived":false,"fork":false,"pushed_at":"2024-05-18T17:36:43.000Z","size":851,"stargazers_count":93,"open_issues_count":46,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-12-06T05:26:18.665Z","etag":null,"topics":["elm","testing"],"latest_commit_sha":null,"homepage":"https://elm-program-test.netlify.com/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avh4.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-21T06:15:24.000Z","updated_at":"2024-05-03T15:40:17.000Z","dependencies_parsed_at":"2024-06-21T14:28:47.353Z","dependency_job_id":null,"html_url":"https://github.com/avh4/elm-program-test","commit_stats":{"total_commits":363,"total_committers":16,"mean_commits":22.6875,"dds":"0.14876033057851235","last_synced_commit":"43d510d302e3e86f92e58e8c2b9372f2b4bd5fd5"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avh4%2Felm-program-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avh4%2Felm-program-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avh4%2Felm-program-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avh4%2Felm-program-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avh4","download_url":"https://codeload.github.com/avh4/elm-program-test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230415317,"owners_count":18222158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","testing"],"created_at":"2024-09-28T08:05:00.087Z","updated_at":"2024-12-19T10:08:52.452Z","avatar_url":"https://github.com/avh4.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Version](https://img.shields.io/elm-package/v/avh4/elm-program-test.svg?label=version)](https://package.elm-lang.org/packages/avh4/elm-program-test/latest/)\n\n# Test Elm Programs\n\n`elm-program-test` provides a convenient API that works with\n[elm-test](http://package.elm-lang.org/packages/elm-explorations/test/latest)\n(including `Test.Html`)\nfor testing your Elm programs as complete units.\n\n## How to install \n\n1. Install the [elm-explorations/test](https://package.elm-lang.org/packages/elm-explorations/test/latest/).\n2. Install the elm-program-test using the command\n\n    ```elm-test install avh4/elm-program-test```\n\n\n## [Guidebooks](https://elm-program-test.netlify.com/#guidebooks)\n\nNote: If you are just looking for a quick example of what using `elm-program-test` looks like,\nsee the [\"basic example\"](#basic-example) below.\n\nFor more detailed documentation, the following guides show examples of how to use\n`elm-program-test` to test different aspects of an Elm program:\n\n- [Testing programs with interactive views](https://elm-program-test.netlify.com/html.html) \u0026mdash;\n  shows an example of test-driving adding form validation to an Elm program\n- [Testing programs with Cmds](https://elm-program-test.netlify.com/cmds.html) \u0026mdash; shows testing a program\n  that uses `Http.get` and `Http.post`\n- [Testing programs with ports](https://elm-program-test.netlify.com/ports.html) \u0026mdash; shows testing a program\n  that uses ports to interface with JavaScript\n- [Upgrading from elm-program-test 2.x to 3.x](https://elm-program-test.netlify.com/upgrade-3.0.0.html)\n\n\n## Basic example\n\nIn this example, `ProgramTest.createElement` and `start` are used to initiate testing of the imagined `MyProgram` module\n(which follows [the Elm architecture](https://guide.elm-lang.org/architecture/)).\nThen `clickButton` is used to simulate user interaction with the program,\nand finally `expectViewHas` is used to assert the final state of the program's displayed HTML.\n\n```elm\nimport Test exposing (..)\nimport Test.Html.Selector exposing (class, text)\nimport ProgramTest exposing (clickButton, expectViewHas, start)\nimport MyProgram -- just an imaginary example\n\nexampleProgramTest : Test\nexampleProgramTest =\n    test \"cannot publish without a title\" \u003c|\n        \\() -\u003e\n            ProgramTest.createElement\n                { init = MyProgram.init\n                , update = MyProgram.update\n                , view = MyProgram.view\n                }\n                |\u003e start ()\n                |\u003e clickButton \"New Post\"\n                |\u003e clickButton \"Publish\"\n                |\u003e expectViewHas\n                    [ class \"invalid-article\"\n                    , text \"You must provide a title before publishing\"\n                    ]\n```\n\n\n## Testing programs with flags and/or navigation\n\nThis example tests a program that requires both [flags](https://guide.elm-lang.org/interop/flags.html) and [navigation](https://package.elm-lang.org/packages/elm/browser/latest/Browser#application).\nThere are variants of the `ProgramTest.create*` functions ([see all](ProgramTest#creating)) for each type of Elm program supported by `elm/browser`,\nand there are a handful of other options that can be used to configure the test before starting it.\n\n```elm\nimport Test exposing (..)\nimport Test.Html.Selector exposing (class, text)\nimport ProgramTest exposing (ProgramTest, clickButton, expectViewHas)\nimport MyProgram exposing (Flags, Msg, Model) -- just an imaginary example\n\nstart : String -\u003e Flags -\u003e ProgramTest Model Msg (Cmd Msg)\nstart initialUrl flags =\n    ProgramTest.createApplication\n        { onUrlChange = MyProgram.OnUrlChange\n        , onUrlRequest = MyProgram.OnUrlRequest\n        , init =\n            -- NOTE: the type of MyProgram.init is:\n            -- MyProgram.Flags -\u003e Navigation.Location -\u003e (MyProgram.Model, Cmd MyProgram.Msg)\n            MyProgram.init\n        , update = MyProgram.update\n        , view = MyProgram.view\n        }\n        |\u003e ProgramTest.withBaseUrl initialUrl\n        |\u003e ProgramTest.start flags\n\nexampleProgramTest : Test\nexampleProgramTest =\n    test \"pages show social media link at the end\" \u003c|\n        \\() -\u003e\n            start \"https://my-program.example.com/page/9\" MyProgram.defaultFlags\n                |\u003e clickButton \"Read More\"\n                |\u003e expectViewHas\n                    [ class \"super-social-link\"\n                    , attribute (href \"https://super.social.example.com/avh4\")\n                    ]\n```\n\n\n## Testing view modules (not full programs)\n\nYou can also use `elm-program-test` to test things that aren't programs by creating a trivial program.\n\nThis example tests a module for a complicated view by making a program with a trivial update function:\n\n```elm\nimport DateTimePicker -- using abadi199/datetimepicker 6.0.0 as an example of a view to test\nimport Test exposing (..)\nimport Test.Html.Selector exposing (text)\nimport ProgramTest exposing (ProgramTest, clickButton, expectViewHas)\n\nstartDatePicker :\n    ProgramTest\n        (DateTimePicker.State, Maybe Date) -- model: simply the state needed by the view being tested\n        (DateTimePicker.State, Maybe Date) -- msg: in this trivial program, the msg is simply the new model value\n        (Cmd never) -- effect: could use any type here, but Cmd seems least confusing\nstartDatePicker =\n    ProgramTest.createElement\n        { init = \\() -\u003e ((DateTimePicker.initialState, Nothing), Cmd.none)\n        , update = newState model -\u003e (newState, Cmd.none)\n        , view =\n            \\(state, value) -\u003e\n                DateTimePicker.dateTimePicker (,) [] state value\n        }\n        |\u003e ProgramTest.start ()\n\ndatePickerTest : Test\ndatePickerTest =\n    test \"can advance to the next month\" \u003c|\n        \\() -\u003e\n            startDatePicker\n                |\u003e clickButton \"Next Month\"\n                |\u003e expectViewHas [ text \"April 2018\" ]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favh4%2Felm-program-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favh4%2Felm-program-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favh4%2Felm-program-test/lists"}