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

FunctionDescription
test(name, condition)Assert a condition. Shows passed/failed in results
response.statusHTTP status code (number)
response.bodyParsed response body (object if JSON, string otherwise)
response.headersResponse headers as key-value object
response.timeResponse time in milliseconds
response.sizeResponse 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

On this page