elm-program-test
elm-program-test copied to clipboard
Feature request: Add ProgramTest.ensurePageChange
There is a expectPageChange
function in the API, but there is no ensurePageChange
.
Context
We would like to have a test that asserts the flow of multiple pages, and the flow includes a click on a link.
-- ...
|> ProgramTest.clickLink "Text" "href"
|> ProgramTest.ensurePageChange "/href"
-- do more assertions once the page has changed
Is there a limitation in the framework to do this, or is it counter to the philosophy of the tool?
ensurePageChange
is meant for when you clicked a link that your app doesn't handle, so the browser is handling it and navigating you to a new URL, so this would correspond to the Elm app being destroyed!
- Are you testing a SPA where your app handled the link click? If so, then you want
ensureBrowserUrl
/expectBrowserUrl
instead. - Is it a link that opens the URL in a new window/tab in the real app? If so, then that's not really implemented yet, see https://github.com/avh4/elm-program-test/issues/90 though I'm not 100% how the API should actually work for that case w/r to checking that the new window/tab was opened.
- If you just want to check that the link is there and then continue in the test, I personally might just
ensureViewHas [ tag "a", attribute (href "href"), containing [ text "Text" ]
- ... or if you really want to check clicking the link, I'd probably do
|> Expect.all [ ProgramTest.clickLink "Text" "href" >> ProgramTest.ensurePageChange "/href" , ... more stuff ... ]
- Or did I miss something? What's the real-world sequence of events you're trying to write a test for? Is the Elm app still running after you click that link?