A TestContext simulates the execution of an Elm program.
Creates a TestContext from the parts of a standard Html.program.
See other create* functions below if the program you want to test
uses flags or nagivation.
Creates a TestContext from the parts of a standard with flags (Html.programWithFlags).
If your program uses Json.Encode.Value as its flags type,
you may find createWithJsonStringFlags useful.
If your program does not use flags, see create.
See other create* functions below if the program you want to test
uses nagivation.
A simplified way to create a TestContext for a program that decodes its flags with a JSON decoder.
If your program does not use Json.Encode.Value as its flags type,
or you want more control over how the flags are provided in your tests,
see createWithFlags.
If your program does not use flags, see create.
See other create* functions below if the program you want to test
uses nagivation.
Simulates clicking a button.
Currently, this function will find and click a <button> HTML node containing the given buttonText.
NOTE: In the future, this function will be generalized to find buttons with accessibility attributes
matching the given buttonText.
Simulates a custom DOM event.
NOTE: If there is another, more specific function (see Simulating user input that does what you want, prefer that instead, as you will get the benefit of better error messages.
Parameters:
findTarget: A function to find the HTML element that responds to the event
(typically this will be a call to Test.Html.Query.find [ ...some selector... ])( eventName, eventValue ): The event to simulate (see Test.Html.Event "Event Builders")url may be an absolute URL or relative URL
Advances the state of the TestContext's program by using the TestContext's program's update function
with the given msg.
This can be used to simulate events that can only be triggered by commands (Cmd) and subscriptions (Sub)
(i.e., that cannot be triggered by user interaction with the view).
NOTE: When possible, you should prefer Simulating user input, as doing so will make your tests more robust to changes in your program's implementation details.
A simpler way to assert that a TestContext's view matches a given selector.
expectViewHas [...selector...] is the same as expectView (Test.Html.Query.has [...selector...]).
Makes an assertion about the current state of a TestContext's view.
Makes an assertion about the last effect produced by a TestContext's program.
Make an assertion about the current state of a TestContext's model.
These functions can be used to make assertions on a TestContext without ending the test.
shouldHave [...selector...] is equivalent to shouldHaveView (Test.Html.Query.has [...selector...])
shouldNotHave [...selector...] is equivalent to shouldHaveView (Test.Html.Query.hasNot [...selector...])
Validates the the current state of a TestContext's view without ending the TestContext.
Validates the last effect produced by a TestContext's program without ending the TestContext.
To end a TestContext without using a final assertion, use the following function:
Ends a TestContext, reporting any errors that occurred.
NOTE: You should prefer using a final assertion to end your test over using done,
as doing so will make the intent of your test more clear.
These functions may be useful if you are writing your own custom assertion functions.
fail can be used to report custom errors if you are writing your own convenience functions to deal with test contexts.
Example (this is a function that checks for a particular structure in the program's view,
but will also fail the TestContext if the expectedCount parameter is invalid):
expectNotificationCount : Int -> TestContext Msg Model effect -> TestContext Msg Model effect
expectNotificationCount expectedCount testContext =
if expectedCount <= 0 then
testContext
|> TestContext.fail "expectNotificationCount"
("expectedCount must be positive, but was: " ++ toString expectedCount)
else
testContext
|> shouldHave
[ Test.Html.Selector.class "notifications"
, Test.Html.Selector.text (toString expectedCount)
]
A
TestContextrepresents an Elm program, a current state for that program, and a log of any errors that have occurred while simulating interaction with the program.TestContext, see thecreate*` functions below.TestContext, see Simulating user input, and Directly sending MsgsTestContext, see Final assertions