novdom_testing/testing
A module for initializing tests and rendering components.
Use it in combination with novdom_testing/component_should
to test novdom components.
Types
A Type for a function that creates a parameter with a listener (e.g. onclick
).
pub type ParameterFn =
fn(fn(Event) -> Nil) -> Parameter
Functions
pub fn call_callee(callee: Callee) -> Nil
Call a callee to later check if it was called (see callee_count
).
Use this function to simulate a function call.
pub fn child(
component: Component,
index: Int,
) -> Result(Component, Nil)
Gets a specific child of a component.
pub fn children(component: Component) -> List(Component)
Gets all children of a component.
pub fn create_callee() -> Callee
Create a callee type that can be used to test if a function was called
pub fn description(
component: Component,
desc: String,
) -> Component
Set a description for a component to be used in error messages
pub fn init(test_fn: fn() -> a) -> Nil
Initialize the testing environment. This function should be called at the beginning of a test.
pub fn render(component: fn() -> Component) -> Nil
Render a component in the viewport. This function should be called in a test function.
Warning: Never use novdom.start()
in a test function, this can lead to unexpected behavior.
pub fn step(subject: a, step: String) -> a
Name a step in a test to make error messages more precise. This does only work with novdom_testing/component_should
functions (not with gleeunit/should
).
Example:
comp
|> step("Check if component is visible")
|> component_should.be_visible()
pub fn trigger_event(
component: Component,
listener: fn(fn(Event) -> Nil) -> Parameter,
) -> Component
Trigger an event on a component.
Example for a click event:
trigger_event(my_component, onclick)
pub fn trigger_replacement(component: Component) -> Component
Trigger the onreplacement
modifier on a component.