Raxol. UI. VisualTest
(Raxol v2.6.0)
View Source
Visual regression testing utilities for Raxol applications.
Provides helpers for capturing screenshots, comparing renders, and detecting visual regressions in component output.
Usage
defmodule MyComponentVisualTest do
use ExUnit.Case
import Raxol.UI.VisualTest
test "button renders correctly" do
result = render_snapshot(MyButton, label: "Click")
assert_snapshot(result, "button_default")
end
test "button hover state" do
result = render_snapshot(MyButton, label: "Click", state: :hover)
assert_snapshot(result, "button_hover")
end
endSnapshot Storage
Snapshots are stored in test/snapshots/ by default. The first run
creates baseline snapshots, subsequent runs compare against them.
Summary
Functions
Assert that two snapshots are different.
Assert that two snapshots are visually identical.
Assert that a snapshot matches the stored baseline.
Compare two renders and return the differences.
Delete a snapshot.
List all snapshots in the snapshot directory.
Render a component and capture it as a snapshot.
Generate a visual diff representation.
Functions
Assert that two snapshots are different.
Example
assert_different(snapshot_a, snapshot_b)
Assert that two snapshots are visually identical.
Example
assert_identical(snapshot_a, snapshot_b)
Assert that a snapshot matches the stored baseline.
On first run, creates the baseline. On subsequent runs, compares against the baseline and fails if different.
Options
:update- Force update the baseline (default: false):snapshot_dir- Custom snapshot directory
Example
assert_snapshot(snapshot, "my_component_default")
Compare two renders and return the differences.
Example
diff = compare_renders(old_snapshot, new_snapshot)
Delete a snapshot.
Example
delete_snapshot("my_component_default")
List all snapshots in the snapshot directory.
Example
snapshots = list_snapshots()
@spec render_snapshot( module(), keyword() ) :: %{ content: String.t(), width: non_neg_integer(), height: non_neg_integer(), component: module(), props: keyword(), checksum: String.t() }
Render a component and capture it as a snapshot.
Options
:width- Buffer width (default: 80):height- Buffer height (default: 24)- Additional options are passed to the component
Example
snapshot = render_snapshot(MyButton, label: "Click", width: 20, height: 3)
Generate a visual diff representation.
Returns a string showing the differences between two snapshots.
Example
diff_text = visual_diff(old_snapshot, new_snapshot)
IO.puts(diff_text)