Skip to main content
hitspec provides 26 assertion operators organized into six categories. Every assertion follows this pattern:
expect <subject> <operator> <value>
When the operator is ==, you can omit it: expect status 200 is shorthand for expect status == 200.

Equality and Comparison (6 operators)

OperatorSyntaxDescription
==expect status == 200Equals (deep equality for objects/arrays, numeric coercion for numbers)
!=expect body.error != nullNot equals
>expect body.count > 0Greater than (numeric)
>=expect body.count >= 1Greater than or equal (numeric)
<expect duration < 1000Less than (numeric)
<=expect duration <= 500Less than or equal (numeric)
>>>
expect status == 200
expect duration < 500
expect body.total > 0
expect body.page >= 1
expect body.errors != null
<<<
Numeric comparison coerces strings to numbers when possible. "42" and 42 are considered equal by ==.

String Operators (5 operators)

OperatorSyntaxDescription
containsexpect body contains "success"Actual value contains the expected substring
!containsexpect body !contains "error"Actual value does not contain the substring
startsWithexpect body.url startsWith "https"Actual value starts with the expected prefix
endsWithexpect body.email endsWith ".com"Actual value ends with the expected suffix
matchesexpect body.id matches /^\d+$/Actual value matches a regular expression
>>>
expect body.email endsWith "@example.com"
expect body.website startsWith "https"
expect body.bio !contains "<script>"
expect body.phone matches /^\+?[\d\s\-()]+$/
<<<
Regular expressions use Go’s regexp syntax and are enclosed in forward slashes: /pattern/.

Existence and Type (3 operators)

OperatorSyntaxDescription
existsexpect body.id existsValue is present and not null
!existsexpect body.error !existsValue is absent or null
typeexpect body.items type arrayValue matches the expected type
Supported type values: null, boolean, number, string, array, object.
>>>
expect body.id exists
expect body.name type string
expect body.age type number
expect body.active type boolean
expect body.tags type array
expect body.address type object
expect body.deletedAt !exists
<<<

Length Operators (5 operators)

OperatorSyntaxDescription
lengthexpect body.items length 10Length equals exact value
length >expect body.items length > 0Length greater than
length >=expect body.items length >= 1Length greater than or equal
length <expect body.items length < 100Length less than
length <=expect body.items length <= 50Length less than or equal
Works on strings, arrays, and objects (counts keys).
>>>
expect body.users length > 0
expect body.users length <= 100
expect body.name length >= 1
<<<

Array Operators (5 operators)

OperatorSyntaxDescription
includesexpect body.tags includes "admin"Array contains the value
!includesexpect body.tags !includes "test"Array does not contain the value
inexpect status in [200, 201, 204]Value is one of the listed values
!inexpect status !in [400, 404, 500]Value is not one of the listed values
eachexpect body.items each type objectAssertion applied to every array element

includes / !includes

Checks whether an array contains (or does not contain) a specific value:
>>>
expect body.permissions includes "read"
expect body.permissions !includes "superadmin"
<<<

in / !in

Checks whether a scalar value is a member of a set. List values in square brackets:
>>>
expect status in [200, 201]
expect body.role in ["admin", "editor", "viewer"]
expect body.status !in ["deleted", "banned"]
<<<

each

Applies an assertion to every element in an array. Useful for validating list shapes:
>>>
expect body.users each type object
<<<
You can also use each with an operator/value map:
>>>
expect body.items each {"operator": "type", "value": "object"}
<<<

Schema and Snapshot (2 operators)

OperatorSyntaxDescription
schemaexpect body schema ./schema.jsonValidate against a JSON Schema file
snapshotexpect body snapshot "name"Compare against a saved snapshot

schema

Validates the response body against a JSON Schema file. File paths are relative to the .http file.
>>>
expect body schema ./schemas/user.json
<<<

snapshot

Compares the response body against a previously saved baseline. On first run, the snapshot is created. On subsequent runs, differences cause failure.
>>>
expect body snapshot "user-profile"
<<<
Update snapshots when the response intentionally changes:
hitspec run tests/ --update-snapshots

Quick Reference

#OperatorCategoryExample
1==Equalityexpect status == 200
2!=Equalityexpect body.error != null
3>Comparisonexpect body.count > 0
4>=Comparisonexpect body.count >= 1
5<Comparisonexpect duration < 1000
6<=Comparisonexpect duration <= 500
7containsStringexpect body contains "ok"
8!containsStringexpect body !contains "error"
9startsWithStringexpect body.url startsWith "https"
10endsWithStringexpect body.email endsWith ".com"
11matchesStringexpect body.id matches /^\d+$/
12existsExistenceexpect body.id exists
13!existsExistenceexpect body.error !exists
14typeTypeexpect body.items type array
15lengthLengthexpect body.items length 10
16length >Lengthexpect body.items length > 0
17length >=Lengthexpect body.items length >= 1
18length <Lengthexpect body.items length < 100
19length <=Lengthexpect body.items length <= 50
20includesArrayexpect body.tags includes "admin"
21!includesArrayexpect body.tags !includes "test"
22inArrayexpect status in [200, 201]
23!inArrayexpect status !in [400, 500]
24eachArrayexpect body.items each type object
25schemaValidationexpect body schema ./schema.json
26snapshotValidationexpect body snapshot "name"