Raxol.Test.Unit.Assertions (Raxol v0.2.0)

View Source

Provides custom assertions for testing Raxol components.

This module includes assertions for:

  • Component state validation
  • Event handling verification
  • Command emission checking
  • Render output validation
  • Layout verification
  • Style application testing

Summary

Functions

Asserts that a component emitted specific commands in sequence.

Asserts that a component properly handles an error condition.

Asserts that a component's layout matches the expected constraints.

Asserts that a component's rendered output matches the expected output.

Asserts that a component's state history includes specific changes.

Asserts that a style is properly applied to a component.

Asserts that a component has specific subscriptions active.

Functions

assert_command_sequence(component, expected_commands)

Asserts that a component emitted specific commands in sequence.

Example

assert_command_sequence component, [
  {:update, :text},
  {:notify, :changed},
  {:submit}
]

assert_handles_error(component, error_fn)

Asserts that a component properly handles an error condition.

Example

assert_handles_error component, fn ->
  simulate_event(component, invalid_event())
end

assert_layout(component, constraints)

Asserts that a component's layout matches the expected constraints.

Example

assert_layout component, %{
  width: 10,
  height: 5,
  x: 0,
  y: 0
}

assert_rendered(component, assertion)

(macro)

Asserts that a component's rendered output matches the expected output.

Example

assert_rendered component, fn output ->
  assert output.type == :text
  assert output.content == "Hello, World!"
end

assert_state_history(component, expected_states)

Asserts that a component's state history includes specific changes.

Example

assert_state_history component, [
  %{text: ""},
  %{text: "Hello"},
  %{text: "Hello, World!"}
]

assert_state_match(actual, expected)

assert_style(component, style)

Asserts that a style is properly applied to a component.

Example

assert_style component, %{
  color: :blue,
  background: :white,
  bold: true
}

assert_subscribed(component, subscription_types)

Asserts that a component has specific subscriptions active.

Example

assert_subscribed component, [:keyboard, :mouse]