Skip to content

test

hc.test(name, fn)

Available since v2.0.0

Signature:(name: string, fn: () => void) => void

Registers a named test. If fn completes without throwing, the test passes. If fn throws (including failed hc.expect assertions), the test fails and the error message is recorded.

Tests are most useful in post-request scripts. Results appear in the response viewer Tests tab after the send completes.

For Postman-style response checks (status, headers, body, JSON), prefer hc.response.to. Use hc.expect(actual) when asserting on arbitrary values.

javascript
hc.test("status is 200", function () {
  hc.response.to.have.status(200);
});