Raxol.Test.Unit (Raxol v0.4.0)

View Source

Provides utilities for unit testing Raxol components and modules.

This module offers a comprehensive set of tools for:

  • Component isolation and testing
  • Event simulation and verification
  • State management testing
  • Render output validation

Example

defmodule MyComponent.Test do
  use ExUnit.Case
  use Raxol.Test.Unit

  test_component "handles keyboard input", MyComponent do
    event = keyboard_event(:enter)
    result = simulate_event(component, event)

    assert_state(component, %{text: ""})
    assert_command_emitted(result, :submit)
  end
end

Summary

Functions

Asserts that a command was emitted by the component.

Asserts that a specific event was handled by the component.

Asserts that a component's state matches the expected state.

Creates a custom event for testing.

Creates a keyboard event for testing.

Sets up a component for isolated testing with initial properties.

Simulates an event being sent to a component.

Creates a window event for testing.

Functions

assert_command_emitted(arg, command)

Asserts that a command was emitted by the component.

assert_event_handled(component, event, expected_result)

Asserts that a specific event was handled by the component.

assert_state(component, expected_state)

Asserts that a component's state matches the expected state.

custom_event(data)

Creates a custom event for testing.

keyboard_event(key)

Creates a keyboard event for testing.

setup_isolated_component(component)

setup_isolated_component(component, props)

Sets up a component for isolated testing with initial properties.

simulate_event(component, event)

Simulates an event being sent to a component.

Returns the updated state and any emitted commands.

test_component(name, component, list)

(macro)

window_event(width, height, action)

Creates a window event for testing.