Skip to content
WebMCP Agents
Esc
↑↓navigate↵open⌘Jpreview
On this page

mount

Mount HTML or a React element into the page; removed after the test.

The mount fixture: puts HTML or a React element into a fresh div.test-fixture and returns it. After the test, React roots are unmounted (a provider releases its tools and its cursor) and the fixtures removed.

Import

import { test } from "@webmcp-agents/testing";

test("…", async ({ mount }) => {});

Example

import { expect, test } from "@webmcp-agents/testing";
import {
  mockAdapter,
  text,
  toolCall,
} from "@webmcp-agents/testing/chat";
import { WebAgentsProvider } from "@webmcp-agents/react";

import { Store, storeAgent } from "./app/store";

test("reorders the last purchase", async ({ tools, mount }) => {
  mount(
    <WebAgentsProvider>
      <Store />
    </WebAgentsProvider>,
  );
  await expect.poll(() => tools.list()).toContain("add_to_cart");
  const adapter = mockAdapter([
    toolCall("track_last_order"),
    toolCall("add_to_cart", { id: "mug-01", qty: 2 }),
    text("Back in your cart."),
  ]);

  const run = await storeAgent.invoke("Reorder my last purchase.", {
    adapter,
  });

  expect(run).toHaveCalledTools(["track_last_order", "add_to_cart"]);
  expect(run).toHaveAnswered("Back in your cart.");
  expect(adapter).toHaveBeenOfferedTools(
    expect.not.arrayContaining(["place_order"]),
  );
});

Options

mount(ui).

Name Type Default Description
ui string | ReactElement required HTML, or a React element (<WebAgentsProvider>…</WebAgentsProvider>).

Returns

HTMLElement: the fixture root the UI was mounted into.

Notes

A React element needs react-dom: without it, mount(<JSX>) fails with a sentence naming it. HTML needs nothing. Browser mode only.

Mountable

What mount accepts: an HTML string, or a React element.

See also

Was this page helpful?