Test the chat UI
Render <AgentChat> with a scripted adapter, your messages, theme or locale, and check that every string on screen comes from the catalog.
renderChat renders <AgentChat>, open, with an adapter you choose and any of its props. Use it to check what your
customizations do: your words, a theme, a replaced part, Arabic with right-to-left layout.
A complete example
import { expect, test } from "@webmcp-agents/testing";
import {
mockAdapter,
renderChat,
text,
} from "@webmcp-agents/testing/chat";
import { userEvent } from "vitest/browser";
test("shows every string from the catalog", async () => {
const chat = await renderChat({
adapter: mockAdapter([text("Two mugs are in your cart.")]),
sentinel: true,
});
await userEvent.type(chat.part("input")!, "Add two mugs{Enter}");
await expect
.poll(() => chat.panel.textContent)
.toContain("Two mugs are in your cart.");
// The person's message and the model's answer are allowed;
// any other text is a string the catalog does not cover.
expect(chat).toHaveNoHardcodedText({
allow: ["Add two mugs", "Two mugs are in your cart."],
});
});
test("uses your words", async () => {
const chat = await renderChat({
props: { messages: { composer: { placeholder: "Ask Field" } } },
});
const input = chat.part("input");
expect(input?.getAttribute("placeholder")).toBe("Ask Field");
});
test("mirrors in Arabic", async () => {
const chat = await renderChat({ props: { locale: "ar" } });
expect(chat.host.closest("[dir]")?.getAttribute("dir")).toBe("rtl");
});
chat.part("input") finds an element by its data-wa-part, the same names you style. chat.host is the chat’s
root, chat.panel its panel.
No string outside the catalog
With sentinel: true, every catalog string is replaced by its key (⟦composer.send⟧). Any other text left on screen,
in an aria-label, a placeholder or a title, was written somewhere the catalog does not reach.
toHaveNoHardcodedText fails with each such string and where it is. List what is allowed: the person’s message and
the model’s answer.
Run it after you replace a part with your own component: it is how you find the label you forgot to translate.