Raxol.MCP.Test.Assertions (Raxol MCP v2.6.0)

Copy Markdown View Source

ExUnit assertion macros for Raxol MCP tests.

All assertions are pipe-friendly -- they return the session on success, so you can chain them:

session
|> click("btn")
|> assert_tool_available("btn.click")
|> assert_component("status", fn c -> c[:content] == "done" end)

Usage

use ExUnit.Case
import Raxol.MCP.Test
import Raxol.MCP.Test.Assertions

Summary

Functions

Asserts a Component with the given ID exists in the current view tree.

Asserts the model matches a predicate function.

Asserts the text screenshot contains the given string.

Asserts the structured Component tree matches an expected shape.

Asserts a tool with the given name is available in the MCP registry.

Asserts that exactly N tools are registered.

Asserts a Component with the given ID does NOT exist in the view tree.

Asserts a tool is NOT available in the MCP registry.

Functions

assert_component(session, component_id, predicate \\ nil)

(macro)

Asserts a Component with the given ID exists in the current view tree.

Optionally takes a predicate function to check Component properties.

assert_component(session, "search_input")
assert_component(session, "counter", fn c -> c[:content] == "5" end)

assert_model(session, predicate)

(macro)

Asserts the model matches a predicate function.

assert_model(session, fn model -> model.count == 5 end)

assert_screenshot_contains(session, text)

(macro)

Asserts the text screenshot contains the given string.

assert_screenshot_contains(session, "Welcome")

assert_screenshot_matches(session, expected)

(macro)

Asserts the structured Component tree matches an expected shape.

The expected value is a list of maps with :type and optionally :id. Uses subset matching -- each expected Component must appear somewhere in the actual tree.

assert_screenshot_matches(session, [
  %{type: :button, id: "submit"},
  %{type: :text_input, id: "name"}
])

assert_tool_available(session, tool_name)

(macro)

Asserts a tool with the given name is available in the MCP registry.

assert_tool_available(session, "search_input.type_into")

assert_tool_count(session, count)

(macro)

Asserts that exactly N tools are registered.

assert_tool_count(session, 5)

refute_component(session, component_id)

(macro)

Asserts a Component with the given ID does NOT exist in the view tree.

refute_component(session, "deleted_item")

refute_tool_available(session, tool_name)

(macro)

Asserts a tool is NOT available in the MCP registry.

refute_tool_available(session, "disabled_btn.click")