PageSourceSearch

https://elm-program-test.netlify.app/assets/js/11.47227962.js

js elm-program-test.netlify.app collected 2026-10-03 10:41:44 UTC 8,958 bytes, 1 lines download raw bytes

1(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{411:function(e,t,a){"use strict";a.r(t);var r=a(56),o=Object(r.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"upgrading-from-elm-program-test-2-x-to-3-x"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#upgrading-from-elm-program-test-2-x-to-3-x"}},[e._v("#")]),e._v(" Upgrading from elm-program-test 2.x to 3.x")]),e._v(" "),a("p",[e._v('The new version of elm-program-test makes some significant changes to show tests are created,\nand makes a handful of other changes to the API.\nThe list items throughout this document starting with "👉" are a checklist of steps to follow when upgrading.')]),e._v(" "),a("h2",{attrs:{id:"new-module-name-programtest"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#new-module-name-programtest"}},[e._v("#")]),e._v(" New module name "),a("code",[e._v("ProgramTest")])]),e._v(" "),a("p",[e._v("The central module in elm-program-test has been renamed from "),a("code",[e._v("TestContext")]),e._v(" to "),a("code",[e._v("ProgramTest")]),e._v(".\nThe new name is meant to be a more conrete and meaningful term,\nand is meant to be easier to remember, as it now matches the package name (elm-program-test).\nThe order of the type arguments has also changed to more closely match "),a("a",{attrs:{href:"https://package.elm-lang.org/packages/elm/core/latest/Platform#Program",target:"_blank",rel:"noopener noreferrer"}}
1,[e._v("elm/core's "),a("code",[e._v("Platform.Program")]),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("ul",[a("li",[e._v("👉 Rename all references to "),a("code",[e._v("TestContext")]),e._v(" -> "),a("code",[e._v("ProgramTest")])]),e._v(" "),a("li",[e._v("👉 swap the order of the first two type arguments of any references to the "),a("code",[e._v("ProgramTest")]),e._v(" type ("),a("code",[e._v("TestContext msg model effect")]),e._v(" becomes "),a("code",[e._v("ProgramTest model msg effect")]),e._v(")")])]),e._v(" "),a("h2",{attrs:{id:"updated-api-for-starting-tests"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#updated-api-for-starting-tests"}},[e._v("#")]),e._v(" Updated API for starting tests")]),e._v(" "),a("p",[e._v("In elm-program-test 2.x, there was a large set of "),a("code",[e._v("create...")]),e._v(" functions\nand you had to choose the one that exactly matches how you wanted to configure your test.\nIn "),a("strong",[e._v("elm-program-test 3.x")]),e._v(", there are now three groups of functions that can be combined in different ways for more flexibility, and the new API is more aligned with the design of Elm 0.19's elm/browser package.  The new groups are as follows:")]),e._v(" "),a("ul",[a("li",[a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#creating-program-definitions",target:"_blank",rel:"noopener noreferrer"}},[a("strong",[a("code",[e._v("create...")])]),e._v(" functions"),a("OutboundLink")],1),e._v(" that parallel the functions in elm/browser that create Programs.  Use the create function that corresponds to the elm/browser function used in your Main module.  (For example, if your program uses "),a("code",[e._v("Browser.document")]),e._v(", then use "),a("code",[e._v("ProgramTest.createDocument")]),e._v(" in your tests.)")]),e._v(" "),a("li",[a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#start",target:"_blank",rel:"noopener noreferrer"}},[e._v("the "),a("strong",[a("code",[e._v("start")])]),e._v(" function"),a("OutboundLink")],1),e._v(" is used to initialize the "),a("code",[e._v("ProgramTest")]),e._v(" state from the "),a("code",[e._v("ProgramDefinition")]),e._v(" created by the "),a("code",[e._v("create...")]),e._v(" functions.  You'll pass the program's inital flags whan calling "),a("code",[e._v("start")]),e._v(" (or pass "),a("code",[e._v("()")]),e._v(" if your program doesn't use flags).")]),e._v(" "),a("li",[a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#options",target:"_blank",rel:"noopener noreferrer"}},[e._v("optional "),a("strong",[a("code",[e._v("with...")])]),e._v(" functions"),a("OutboundLink")],1),e._v(" that can be used to further configure your test before calling "),a("code",[e._v("start")]),e._v(".")])]),e._v(" "),a("p",[e._v("You'll need to familiarize yourself with the "),a("code",[e._v("create...")]),e._v(" and "),a("code",[e._v("start")]),e._v(" functions\nand update to the new API in a way that's appropriate for your specific program.")]),e._v(" "),a("ul",[a("li",[e._v("👉 Update creation of your tests to use the new API")])]),e._v(" "),a("h2",{attrs:{id:"updated-api-for-assertions"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#updated-api-for-assertions"}},[e._v("#")]),e._v(" Updated API for assertions")]),e._v(" "),a("p",[e._v('All assertion/"should"/"expect" functions have been updated to have more consistent naming.\nThere are now two parallel functions for each assertion:\none starting with '),a("code",[e._v("expect...")]),e._v(" which returns an "),a("code",[e._v("Expectation")]),e._v(", meaning it should be used at the end of a test;\nand one starting with "),a("code",[e._v("ensure...")]),e._v(" which returns a "),a("code",[e._v("ProgramTest")]),e._v(", meaning it can be used in the middle of a test.")]),e._v(" "),a("p",[e._v("Here's a full list of changes to existing assertion functions.")]),e._v(" "),a("ul",[a("li",[e._v("👉 Rename uses of the following functions:\n"),a("ul",[a("li",[a("code",[e._v("assertHttpRequest")]),e._v(" ->
1 "),a("code",[e._v("expectHttpRequestWasMade")]),e._v(" (and it now takes the method and URL as two String parameters instead of as fields in a record parameter)")]),e._v(" "),a("li",[a("code",[e._v("shouldHave")]),e._v(" -> "),a("code",[e._v("ensureViewHas")])]),e._v(" "),a("li",[a("code",[e._v("shouldNotHave")]),e._v(" -> "),a("code",[e._v("ensureViewHasNot")])]),e._v(" "),a("li",[a("code",[e._v("shouldHaveView")]),e._v(" -> "),a("code",[e._v("ensureView")])]),e._v(" "),a("li",[a("code",[e._v("shouldHaveLastEffect")]),e._v(" -> "),a("code",[e._v("ensureLastEffect")])])])])]),e._v(" "),a("h2",{attrs:{id:"other-renamed-functions"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#other-renamed-functions"}},[e._v("#")]),e._v(" Other renamed functions")]),e._v(" "),a("ul",[a("li",[e._v("👉 Rename uses of the following functions:\n"),a("ul",[a("li",[a("code",[e._v("simulate")]),e._v(" -> "),a("code",[e._v("simulateDomEvent")])])])])]),e._v(" "),a("h2",{attrs:{id:"direct-support-for-http-ports-and-time"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#direct-support-for-http-ports-and-time"}},[e._v("#")]),e._v(" Direct support for HTTP, ports, and time")]),e._v(" "),a("p",[e._v("If you are currently using "),a("code",[e._v("expectLastEffect")]),e._v(" or "),a("code",[e._v("simulateLastEffect")]),e._v("\nto test functionality related to HTTP requests, Elm ports, or "),a("code",[e._v("Task.sleep")]),e._v(",\nthere is now a much nicer API that you can use.")]),e._v(" "),a("p",[e._v("See the API documentation for\n"),a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#expectHttpRequestWasMade",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("expectHttpRequestWasMade")]),a("OutboundLink")],1),e._v(",\n"),a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#simulateHttpOk",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("simulateHttpOk")]),a("OutboundLink")],1),e._v(",\n"),a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#expectOutgoingPortValues",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("expectOutgoingPortValues")]),a("OutboundLink")],1),e._v(",\n"),a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#simulateIncomingPort",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("simulateIncomingPort")]),a("OutboundLink")],1),e._v(",\nand "),a("a",{attrs:{href:"https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest#advanceTime",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("advanceTime")]),a("OutboundLink")],1),e._v(" for more information.\nThere are also new guidebooks "),a("RouterLink",{attrs:{to:"/cmds.html"}},[e._v("“Testing programs with Cmds”")]),e._v("\nand "),a("RouterLink",{attrs:{to:"/ports.html"}},[e._v("“Testing programs with ports”")]),e._v("\noffering a more detailed example of how to set up such tests.")],1),e._v(" "),a("ul",[a("li",[e._v("👉 Replace calls to "),a("code",[e._v("expectLastEffect")]),e._v(" and "),a("code",[e._v("simulateLastEffect")]),e._v(" with the nicer new API where possible")])])])}),[],!1,null,null,null);t.default=o.exports}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.