{"id":21447263,"url":"https://github.com/brian-watkins/elmer-http","last_synced_at":"2025-03-17T01:43:51.002Z","repository":{"id":81646754,"uuid":"184955522","full_name":"brian-watkins/elmer-http","owner":"brian-watkins","description":"Elmer extension for describing the behavior of Elm apps that use HTTP","archived":false,"fork":false,"pushed_at":"2019-05-12T11:33:08.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T11:34:33.631Z","etag":null,"topics":["elm","testing"],"latest_commit_sha":null,"homepage":"","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/brian-watkins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2019-05-04T23:56:45.000Z","updated_at":"2019-05-12T11:32:39.000Z","dependencies_parsed_at":"2023-07-15T15:20:48.140Z","dependency_job_id":null,"html_url":"https://github.com/brian-watkins/elmer-http","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-watkins%2Felmer-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-watkins%2Felmer-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-watkins%2Felmer-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brian-watkins%2Felmer-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brian-watkins","download_url":"https://codeload.github.com/brian-watkins/elmer-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243960449,"owners_count":20375101,"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-11-23T03:09:30.677Z","updated_at":"2025-03-17T01:43:50.995Z","avatar_url":"https://github.com/brian-watkins.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elmer.Http\n\nThis is an extension for [Elmer](https://github.com/brian-watkins/elmer) that adds test functions and\nmatchers for describing the behavior of Elm apps that use HTTP.\n\n\n### Requirements\n\n- [Elmer](https://github.com/brian-watkins/elmer) - Version 6.x\n- [elm/http](https://github.com/elm/http) - Version 2.x\n\nIf you're interested in using Elmer.Http with elm/http version 1.0.0 then you'll need the\n1.0.0 release of this package.\n\n\n### Getting Started\n\nFirst, you need to install Elmer 6.x in your project. See the documentation\nfor [Elmer](https://github.com/brian-watkins/elmer) for more information on installing the latest version.\n\nNext, you should clone this repository and copy or link the src files into your tests directory.\n\n\n### Documentation\n\nRead the latest docs [here](https://elmer-test.cfapps.io/elmer.http).\n\n\n### Releases\n\n#### 2.0.0\n- Basic support for elm/http 2.0.0\n- Use `Http.get`, `Http.post`, `Http.request`, and `Http.Task` during a test.\n\n#### 1.0.0\n- Basic support for elm/http 1.0.0\n- Use `Http.send` and `Http.toTask` during a test.\n\n\n### Usage\n\nModern web apps often need to make HTTP requests to some backend server. Elmer makes it easy to stub HTTP\nresponses and write expectations about the requests made. The `Elmer.Http.Stub` module contains methods\nfor constructing an `HttpResponseStub` that describes how to respond to some request. For example,\nwe might stub a request to the server for our game to return high scores like so:\n\n```\nlet\n  stubbedResponse = Elmer.Http.Stub.for (Elmer.Http.Route.get \"http://fakeGameServer.com/scores\")\n    |\u003e Elmer.Http.Stub.withBody \"[{\\\"score\\\":700,\\\"player\\\":\\\"Brian\\\"},{\\\"score\\\":900,\\\"player\\\":\\\"Holly\\\"}]\"\nin\n```\n\nIn this case, a GET request to the given route will result in a response with the given body.\nSee `Elmer.Http.Stub` for the full list of builder functions.\n\nOnce an `HttpResponseStub` has been created, you can use the `Elmer.Http.serve` function\nalong with `Elmer.Spy.use` to override `Http.send` and `Http.toTask` from [elm/http](https://package.elm-lang.org/packages/elm/http/latest/) during your test.\nWhen your application code calls `Http.send` or `Http.toTask`, the request will be checked against the\nprovided stubs and if a match occurs, the given response will be returned.\n\nHere's how we can extend our test to describe more of its pre-conditions:\n\n```\nallTests : Test\nallTests =\n  describe \"My Fun Game\"\n  [ describe \"High Score Screen\"\n    [ test \"it shows the high scores\" \u003c|\n      \\() -\u003e\n        let\n          stubbedResponse =\n            Elmer.Http.Stub.for (Elmer.Http.Route.get \"http://fakeGameServer.com/scores\")\n              |\u003e Elmer.Http.Stub.withBody \n                \"[{\\\"score\\\":700,\\\"player\\\":\\\"Brian\\\"},{\\\"score\\\":900,\\\"player\\\":\\\"Holly\\\"}]\"\n        in\n          Elmer.Program.givenElement App.view App.update\n            |\u003e Elmer.Spy.use [ Elmer.Http.serve [ stubbedResponse ] ]\n            |\u003e Elmer.Program.init (\\_ -\u003e App.init testFlags)\n            |\u003e Elmer.Html.target\n                \u003c\u003c Elmer.Html.Selector.childrenOf \n                  [ Elmer.Html.Selector.tag \"ol\"\n                  , Elmer.Html.Selector.class \"score-list\"\n                  ]\n                \u003c\u003c Elmer.Html.Selector.by\n                  [ Elmer.Html.Selector.tag \"li\" ]\n            |\u003e Elmer.Html.expect (Elmer.Html.Matchers.elements \u003c|\n                Elmer.expectAll\n                [ Elmer.hasLength 2\n                , Elmer.atIndex 0 \u003c| Elmer.Html.Matchers.hasText \"700 Points\"\n                , Elmer.atIndex 1 \u003c| Elmer.Html.Matchers.hasText \"900 Points\"\n                ]\n              )\n    ]\n  ]\n```\n\nElmer also allows you to write tests that expect some HTTP request to have been made, in a\nmanner similar to how you can write expectations about some element in an HTML document. For\nexample, this test inputs search terms into a field, clicks a search button, and then expects\nthat a request is made to a specific route with the search terms in the query string:\n\n```\nElmer.given App.defaultModel App.view App.update\n  |\u003e Elmer.Spy.use [ Elmer.Http.serve [ stubbedResponse ] ]\n  |\u003e Elmer.Html.target \u003c\u003c by [ tag \"input\", attribute (\"name\", \"query\") ]\n  |\u003e Elmer.Html.Event.input \"Fun Stuff\"\n  |\u003e Elmer.Html.target \u003c\u003c by [ id \"search-button\" ]\n  |\u003e Elmer.Html.Event.click\n  |\u003e Elmer.Http.expect (Elmer.Http.Route.get \"http://fake.com/search\") (\n    Elmer.some \u003c| Elmer.Http.Matchers.hasQueryParam (\"q\", \"Fun Stuff\")\n  )\n```\n\nIf you don't care to describe the behavior of your app after the response from a request is\nreceived -- that is, if you don't care to create a stubbed response for some request -- you\ncan provide `Elmer.Http.spy` to `Elmer.Spy.use` and it will override the `Http.send` and `Http.toTask`\nfunctions so that they merely record any requests received.\n\nSee `Elmer.Http` and `Elmer.Http.Matchers` for more.\n\n\n#### Deferred Commands\n\nIt's often necessary to describe the behavior of an application while some command is running. For example,\none might want to show a progress indicator while an HTTP request is in process. Elmer provides\ngeneral support for deferred commands. Use `Elmer.Command.defer` to create a command that\nwill not be processed until `Elmer.resolveDeferred` is called. Note that all currently\ndeferred commands will be resolved when this function is called.\n\n`Elmer.Http` allows you to specify when the processing of a stubbed response should be deferred.\nWhen you create your `HttpResponseStub` just use the `Elmer.Http.Stub.deferResponse` builder function\nto indicate that this response should be deferred until `Elmer.resolveDeferred` is called.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrian-watkins%2Felmer-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrian-watkins%2Felmer-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrian-watkins%2Felmer-http/lists"}