Skip to content

expect

hc.expect(actual)

Available since v2.0.0

Signature:(actual: unknown, message?: string) => Assertion

Returns a Chai.js BDD assertion helper for use inside hc.test. Failed assertions throw with a descriptive message. HarborClient uses the same assertion library Postman bundles for pm.expect.

Pass an optional second argument to customize the failure message:

See the Chai BDD API reference for the full matcher list. Common matchers:

javascript
hc.expect(hc.response.code, "expected success status").to.equal(200);

hc.expect(actual).to.be.ok

Available since v2.0.0

Asserts that actual is truthy.

Additional examples:

javascript
hc.expect(hc.response.headers["content-type"]).to.be.ok;
javascript
hc.expect(hc.response.code).to.be.oneOf([200, 201, 204]);
hc.expect(hc.response.status).to.be.a("string");
hc.expect(hc.response.json()).to.have.property("id");

hc.expect(actual).to.eql(expected)

Available since v2.0.0

Deep equality. Use for objects and arrays. Key order does not matter.

javascript
hc.expect(hc.response.json()).to.eql({ ok: true });

hc.expect(actual).to.equal(expected)

Available since v2.0.0

Strict equality (===). Use for primitives and reference checks.

javascript
hc.expect(hc.response.code).to.equal(200);
hc.expect(hc.response.status).to.equal("OK");

hc.expect(actual).to.include(value)

Available since v2.0.0

Asserts that actual contains value — works on strings, arrays, and objects.

javascript
hc.expect(hc.response.text()).to.include('"ok":true');
hc.expect(hc.response.json().items).to.include("active");