Write test cases as natural language instructions that AI agents execute autonomously. No test runner needed — just tell your agent to run the tests.
Create .rnatest.js (or .ts, .tsx, .jsx) files anywhere in your project:
const { describe, it, beforeEach } = require('react-native-agentkit/test');
module.exports = describe('Login Flow', () => {
beforeEach(`
Make sure we are on the login screen
`);
it('should login with valid credentials', `
Clear the email input and type "user@test.com"
Clear the password input and type "password123"
Tap the submit button
The Home screen should appear with a welcome message
`);
it('should show error for invalid credentials', `
Type "wrong@test.com" into the email input
Type "badpass" into the password input
Tap submit
An error message should be visible
We should still be on the login screen
`);
});Write each test step exactly as you'd describe it to an AI assistant:
- Actions: "Tap the submit button", "Type 'hello' into the search input", "Scroll down on the main list", "Toggle dark mode on"
- Assertions: "The home screen should appear", "The cart badge should show '3'", "The error message should be visible"
- Navigation: "Navigate to the Settings tab", "Go back to the previous screen"
- Waiting: "Wait for the loading spinner to disappear"
Each line is a separate instruction. Be descriptive — the AI agent uses the screen state to figure out which elements match your description.
| Function | Purpose | Required |
|---|---|---|
describe(name, fn) |
Group tests into a suite | Yes |
it(name, instructions) |
Define a single test case | Yes |
test(name, instructions) |
Alias for it |
— |
beforeAll(instructions) |
Run once before all tests in this suite | No |
afterAll(instructions) |
Run once after all tests in this suite | No |
beforeEach(instructions) |
Run before each test | No |
afterEach(instructions) |
Run after each test | No |
Organize larger test suites with nested describe blocks:
const { describe, it, beforeAll, beforeEach } = require('react-native-agentkit/test');
module.exports = describe('My App', () => {
beforeAll(`
Launch the app and wait for it to fully load
`);
describe('Authentication', () => {
it('should show login screen on first launch', `
The login screen should be visible
Email and password inputs should be present
`);
it('should login and show dashboard', `
Enter valid credentials and tap login
The dashboard screen should appear
`);
});
describe('Settings', () => {
beforeEach(`Navigate to the Settings tab`);
it('should toggle notifications', `
Find the notifications switch
Toggle it off
It should now be unchecked
Toggle it back on
It should now be checked
`);
});
});Tell your AI agent:
"I have test cases in the project. Go run them."
Or more specifically:
"Run the login tests in
__tests__/login.rnatest.js"
The agent will:
- Search for
.rnatest.*files in your project - Read each test file to understand the test structure
- Execute each test by translating natural language instructions into AgentKit commands
- Report pass/fail results for each test
Test Results: Login Flow
✅ should login with valid credentials
❌ should show error for invalid credentials
Step failed: "An error message should be visible"
Reason: No element matching "error" found on screen
2 tests: 1 passed, 1 failed
- Be descriptive — "Tap the blue Submit button at the bottom" is better than "Tap submit"
- One action per line — Makes it easier for the agent to execute step by step
- Use testIDs — Reference elements by their
testIDwhen possible for reliability - Keep tests independent — Each
itblock should work on its own (usebeforeEachfor setup) - Test the happy path first — Start with working flows before edge cases