Assertions & Expectations
Assertions & Expectations
Section titled “Assertions & Expectations”RestIO includes a built-in assertion engine powered by Chai-compatible expect syntax and high-level rio.response assertions.
The rio.test() Function
Section titled “The rio.test() Function”All test assertions are grouped inside rio.test(name, fn). Each test can be synchronous or asynchronous:
rio.test("Status code is 200 OK", function () { rio.response.to.have.status(200);});
rio.test("Async validation test", async function () { const json = rio.response.json(); rio.expect(json.items.length).to.be.greaterThan(0);});High-Level Response Matchers
Section titled “High-Level Response Matchers”RestIO provides intuitive shorthand assertions directly on rio.response:
Status Code Checks
Section titled “Status Code Checks”// Assert exact status coderio.response.to.have.status(200);rio.response.to.have.status(201);
// Assert 2xx status familyrio.response.to.be.success;
// Assert 4xx client error familyrio.response.to.be.clientError;
// Assert 5xx server error familyrio.response.to.be.serverError;Header Checks
Section titled “Header Checks”// Check header presencerio.response.to.have.header("content-type");
// Check header presence and exact/partial valuerio.response.to.have.header("content-type", "application/json");Chai-Compatible rio.expect() Matchers
Section titled “Chai-Compatible rio.expect() Matchers”For detailed validation of JSON payloads, data structures, and numbers, use rio.expect():
const body = rio.response.json();
// Type checksrio.expect(body.id).to.be.a("number");rio.expect(body.name).to.be.a("string");rio.expect(body.roles).to.be.an("array");rio.expect(body.active).to.be.a("boolean");
// Value comparisonsrio.expect(body.name).to.equal("Alice");rio.expect(body.age).to.be.at.least(18);rio.expect(body.score).to.be.within(0, 100);
// Property presencerio.expect(body).to.have.property("email");rio.expect(body).to.include.keys("id", "name", "email");
// Array contentsrio.expect(body.roles).to.include("admin");rio.expect(body.tags).to.have.lengthOf(3);
// Regular expressionsrio.expect(body.email).to.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
// Performance / Latency checkrio.expect(rio.response.responseTime).to.be.below(500); // msReading Response Data
Section titled “Reading Response Data”| Method / Property | Description | Return Type |
|---|---|---|
rio.response.code |
The numeric HTTP status code (e.g. 200, 404) |
number |
rio.response.status |
The HTTP status reason string (e.g. "OK", "Not Found") |
string |
rio.response.responseTime |
Total round-trip execution latency in milliseconds | number |
rio.response.json() |
Parses the body string as a JavaScript object | any |
rio.response.text() |
Returns the raw, unparsed response body string | string |
rio.response.headers.get("name") |
Retrieves header value (case-insensitive lookup) | string | null |
Test Results Display
Section titled “Test Results Display”When a request finishes:
- Open the Tests tab in the Response Panel.
- RestIO shows a summary badge (e.g.
Passed: 4 | Failed: 1). - Failed tests display clear, highlighted diffs and assertion error messages (e.g.,
AssertionError: expected 404 to equal 200).
