Documentation Index
Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
@frontmcp/testing extends Jest’s expect with MCP-specific matchers that provide cleaner assertions and better error messages.
Tool Matchers
toContainTool
Check if a tools array contains a tool by name:Result Matchers
toBeSuccessful
Check if a tool call or resource read succeeded:toBeError
Check if a result is an error, optionally with a specific error code:| Code | Name | Description |
|---|---|---|
-32700 | Parse error | Invalid JSON |
-32600 | Invalid request | Invalid JSON-RPC |
-32601 | Method not found | Unknown method |
-32602 | Invalid params | Invalid parameters |
-32603 | Internal error | Server error |
-32001 | Unauthorized | Authentication required |
-32002 | Resource not found | Resource doesn’t exist |
-32800 | Request cancelled | Request was cancelled |
Content Matchers
toHaveTextContent
Check if a result contains text content:toHaveImageContent
Check if a result contains image content:toHaveResourceContent
Check if a result contains embedded resource content:toHaveMimeType
Check the MIME type of resource content:Resource Matchers
toContainResource
Check if a resources array contains a resource by URI:toContainResourceTemplate
Check if a resource templates array contains a template:Prompt Matchers
toContainPrompt
Check if a prompts array contains a prompt by name:toHaveMessages
Check the number of messages in a prompt result:Inspecting message role / content
For role and text-content checks on prompt messages, read the message directly. ThetoHaveTextContent matcher works for tool results; for prompt messages use plain Jest assertions:
JSON-RPC Matchers
toBeValidJsonRpc
Validate JSON-RPC response structure:toHaveResult
Check that a response has a result (not an error):toHaveError
Check that a response is an error:toHaveErrorCode
Check for a specific error code:UI Matchers
These assert on the rendered UI metadata returned by tools that ship a UI template (see Building tool UI). They run againstresult._meta / result.content[0].text (the rendered HTML).
| Matcher | What it checks |
|---|---|
toHaveRenderedHtml() | Result includes a non-empty rendered HTML payload |
toContainHtmlElement(tag) | Rendered HTML contains an element of tag (e.g. 'button') |
toContainBoundValue(v) | Rendered HTML contains the bound input/output value |
toBeXssSafe() | Rendered HTML has been sanitized (no <script>, inline event attrs) |
toHaveWidgetMetadata() | Result advertises the MCP widget metadata block |
toHaveCssClass(name) | Rendered HTML contains an element with the given CSS class |
toNotContainRawContent(s) | Rendered HTML does not contain the raw (unsanitized) string s |
toHaveProperHtmlStructure() | Rendered HTML is well-formed (open/close, no obvious truncation) |
toHavePlatformMeta(p) | Result includes the platform-specific meta block (e.g. 'openai') |
toHaveMetaKey(k) | Result _meta contains key k |
toHaveMetaValue(k, v) | Result _meta[k] deep-equals v |
toNotHaveMetaKey(k) | Result _meta does NOT contain key k |
toHaveOnlyNamespacedMeta(ns) | All _meta keys are namespaced under ns |
toHavePlatformMimeType(p) | Result has the expected MIME type for platform p |
toHavePlatformHtml(p) | Result includes platform-targeted HTML for platform p |
Using with Negation
All matchers support.not for negation:
TypeScript Support
The matchers are fully typed. TypeScript will autocomplete matcher names and validate arguments:Best Practices
Do:- Use specific matchers for clearer error messages
- Combine matchers for comprehensive validation
- Use error code constants instead of magic numbers
- Check internal implementation details
- Use generic
.toBe(true)when specific matchers exist - Ignore error codes in failure tests