ui.assert_text
Verify UI elements display expected text content in iOS Simulator during React Native/Expo testing. Specify element selector and text to validate exact or partial matches.
Instructions
Assert that an element has specific text content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | Element selector. | |
| text | Yes | Expected text content. | |
| exact | No | Exact match (true) or contains (false). |
Implementation Reference
- src/mcp/server.ts:655-683 (handler)Registration and inline handler implementation for the 'ui.assert_text' tool. Generates a Detox snippet for text assertion and executes it via runDetoxAction, returning the result.server.tool( "ui.assert_text", "Assert that an element has specific text content", UiAssertTextInputSchema.shape, async (args) => { try { const snippet = generateAssertTextSnippet({ selector: args.selector, text: args.text, exact: args.exact, }); const result = await runDetoxAction({ actionName: `assertText:${describeSelector(args.selector)}`, actionSnippet: snippet, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (error) { return handleToolError(error); } } );
- src/mcp/schemas.ts:92-96 (schema)Zod input schema defining parameters for the ui.assert_text tool: selector, text, and optional exact match flag.export const UiAssertTextInputSchema = z.object({ selector: SelectorSchema.describe("Element selector."), text: z.string().describe("Expected text content."), exact: z.boolean().optional().default(true).describe("Exact match (true) or contains (false)."), });
- src/detox/actions.ts:128-137 (helper)Helper function that generates the Detox code snippet for asserting text content on a UI element, supporting exact or partial matches.export function generateAssertTextSnippet(options: AssertTextOptions): string { const el = buildElementExpr(options.selector); const escapedText = JSON.stringify(options.text); if (options.exact !== false) { return `await expect(${el}).toHaveText(${escapedText});`; } // For partial text match, we use toHaveText with regex return `await expect(${el}).toHaveText(new RegExp(${escapedText}));`; }