Raxol.Test.Visual (Raxol v0.2.0)

View Source

Provides utilities for visual testing of Raxol components.

This module handles:

  • Component rendering verification
  • Layout testing
  • Style validation
  • Terminal output comparison
  • Cross-terminal compatibility testing

Example

defmodule MyComponent.VisualTest do
  use ExUnit.Case
  use Raxol.Test.Visual

  test "renders correctly" do
    component = setup_visual_component(MyComponent)

    assert_renders_as component, fn output ->
      assert output =~ "Expected Content"
      assert_layout_matches output, width: 10, height: 5
    end
  end
end

Summary

Functions

Verifies that a component renders as expected.

Captures the rendered output of a component.

Compares a component's current render with its snapshot.

Sets up a component for visual testing.

Creates or updates a snapshot of the component's rendered output.

Tests a component's rendering across different terminal sizes.

Tests a component's rendering with different style themes.

Functions

assert_renders_as(component, assertions)

Verifies that a component renders as expected.

Takes a function that can make assertions about the rendered output.

capture_render(component)

Captures the rendered output of a component.

Returns the terminal output as a string for comparison.

compare_with_snapshot(component, name, context)

Compares a component's current render with its snapshot.

Returns a detailed diff if there are differences.

setup_visual_component(module, props \\ %{})

Sets up a component for visual testing.

This function:

  1. Initializes the component
  2. Sets up the render context
  3. Configures the test terminal
  4. Prepares snapshot directories

snapshot_component(component, name, context)

Creates or updates a snapshot of the component's rendered output.

Used for visual regression testing.

test_responsive_rendering(component, sizes)

Tests a component's rendering across different terminal sizes.

Verifies responsive behavior and layout adaptability.

test_themed_rendering(component, themes)

Tests a component's rendering with different style themes.

Verifies proper style application and theme switching.