TermUI.Test.Assertions (TermUI v0.2.0)
View SourceTUI-specific assertion helpers for testing.
Provides assertions for checking rendered content, styles, component state, and focus. Assertions produce clear failure messages showing expected vs actual.
Usage
use TermUI.Test.Assertions
# Content assertions
assert_text(renderer, 1, 1, "Hello")
assert_text_contains(renderer, 1, 1, 80, "Error")
refute_text(renderer, 1, 1, "Goodbye")
# Style assertions
assert_style(renderer, 1, 1, fg: :red)
assert_attr(renderer, 1, 1, :bold)
# State assertions
assert_state(state, [:counter, :value], 42)
Summary
Functions
Imports all assertion macros.
Asserts that a cell has a specific attribute.
Asserts that buffer is empty (all spaces with default style).
Asserts row matches expected text (trimming trailing spaces).
Asserts that a snapshot matches the current buffer.
Asserts state at a path matches expected value.
Asserts state at a path exists (is not nil).
Asserts that a cell has the expected style.
Asserts that text appears at the given position.
Asserts that a region contains the expected text.
Asserts that text exists somewhere in the buffer.
Asserts that a cell does not have a specific attribute.
Asserts state at a path does not match value.
Asserts that text does not appear at the given position.
Asserts that a region does not contain the text.
Asserts that text does not exist anywhere in the buffer.
Functions
Imports all assertion macros.
Example
defmodule MyTest do
use ExUnit.Case
use TermUI.Test.Assertions
test "renders correctly" do
{:ok, renderer} = TestRenderer.new(24, 80)
assert_text(renderer, 1, 1, "Hello")
end
end
Asserts that a cell has a specific attribute.
Examples
assert_attr(renderer, 1, 1, :bold)
Asserts that buffer is empty (all spaces with default style).
Asserts row matches expected text (trimming trailing spaces).
Asserts that a snapshot matches the current buffer.
Examples
snapshot = TestRenderer.snapshot(renderer)
# ... operations ...
assert_snapshot(renderer, snapshot)
Asserts state at a path matches expected value.
Examples
assert_state(%{counter: %{value: 42}}, [:counter, :value], 42)
assert_state(state, [:items], [1, 2, 3])
Asserts state at a path exists (is not nil).
Asserts that a cell has the expected style.
Options
:fg- Expected foreground color:bg- Expected background color:attrs- Expected attributes (list or MapSet)
Examples
assert_style(renderer, 1, 1, fg: :red)
assert_style(renderer, 1, 1, fg: :red, bg: :white)
assert_style(renderer, 1, 1, attrs: [:bold, :underline])
Asserts that text appears at the given position.
Examples
assert_text(renderer, 1, 1, "Hello")
Asserts that a region contains the expected text.
Examples
assert_text_contains(renderer, 1, 1, 80, "Error")
Asserts that text exists somewhere in the buffer.
Examples
assert_text_exists(renderer, "Error")
Asserts that a cell does not have a specific attribute.
Asserts state at a path does not match value.
Asserts that text does not appear at the given position.
Asserts that a region does not contain the text.
Asserts that text does not exist anywhere in the buffer.