Tests
Write assertions to validate API responses automatically after each request.
Tests run automatically after a response is received. Use them to verify status codes, response bodies, headers, and performance. Results are displayed below the response panel.
API Reference
| Function | Description |
|---|---|
| test(name, condition) | Assert a condition. Shows passed/failed in results |
| response.status | HTTP status code (number) |
| response.body | Parsed response body (object if JSON, string otherwise) |
| response.headers | Response headers as key-value object |
| response.time | Response time in milliseconds |
| response.size | Response body size in bytes |
Examples
Test status code
javascript
test("Status is 200", response.status === 200); Test response body
javascript
test("Has results", response.body.results && response.body.results.length > 0);
test("Name matches", response.body.name === "Byron"); Test headers
javascript
test("Content-Type is JSON", response.headers["content-type"] === "application/json"); Test performance
javascript
test("Response under 1 second", response.time < 1000);
test("Response under 500 KB", response.size < 500000); Combined test suite for PokeAPI
javascript
test("Status is 200", response.status === 200);
test("Has data", response.body !== undefined);
test("Has results array", Array.isArray(response.body.results));
test("At least one pokemon", response.body.results.length > 0);
test("First pokemon has name", typeof response.body.results[0].name === "string"); Learn more
- Pre-request Scripts — run code before sending
On this page
Racoon