Assertion Operators Reference
Complete reference for all operators available in Nidra assertions.
Comparison Operators
equals
Value must match exactly.
Field "status" equals "success"
Field "count" equals 42
Field "active" equals true
Data Types: string, number, boolean, null
not equals
Value must be different.
Field "error" not equals null
Field "status" not equals "failed"
Status Code not equals 500
Data Types: string, number, boolean, null
greater than
Numeric comparison.
Field "count" greater than 0
Field "price" greater than 9.99
Response time greater than 100
Data Types: number
greater than or equal
Numeric comparison (inclusive).
Field "age" greater than or equal 18
Field "quantity" greater than or equal 1
Data Types: number
less than
Numeric comparison.
Response time less than 500
Field "discount" less than 100
Field "rating" less than 5.0
Data Types: number
less than or equal
Numeric comparison (inclusive).
Field "progress" less than or equal 100
Field "attempts" less than or equal 3
Data Types: number
String Operators
contains
String contains substring.
Field "email" contains "@example.com"
Field "message" contains "success"
Response body contains "user"
Data Types: string
Case Sensitive: Yes (unless case-insensitive mode)
does not contain
String does not contain substring.
Field "email" does not contain "test"
Response body does not contain "error"
Data Types: string
starts with
String begins with prefix.
Field "userId" starts with "USR_"
Field "url" starts with "https://"
Data Types: string
ends with
String ends with suffix.
Field "filename" ends with ".pdf"
Field "email" ends with "@company.com"
Data Types: string
matches regex
String matches regular expression.
Field "phone" matches regex "^\d{3}-\d{3}-\d{4}$"
Field "zipCode" matches regex "^\d{5}$"
Field "uuid" matches regex "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
Data Types: string
Syntax: JavaScript regex (without delimiters)
Existence Operators
exists
Field must be present (any value).
Field "userId" exists
Field "createdAt" exists
Header "Content-Type" exists
Data Types: any
does not exist
Field must be absent.
Field "error" does not exist
Field "deletedAt" does not exist
Data Types: any
is null
Value must be null.
Field "middleName" is null
Field "canceledAt" is null
Data Types: null
is not null
Value must not be null.
Field "userId" is not null
Field "email" is not null
Data Types: any except null
Type Operators
is type
Value must be of specified type.
Field "id" is type "number"
Field "email" is type "string"
Field "active" is type "boolean"
Field "tags" is type "array"
Field "user" is type "object"
Field "optional" is type "null"
Supported Types:
stringnumberbooleanarrayobjectnull
Collection Operators
is empty
Array or object has no elements.
Field "errors" is empty
Field "tags" is empty
Data Types: array, object
is not empty
Array or object has at least one element.
Field "results" is not empty
Field "items" is not empty
Data Types: array, object
length equals
Exact number of elements.
Field "items" length equals 5
Field "name" length equals 10 // string length
Data Types: array, object, string
length greater than
More than N elements.
Field "results" length greater than 0
Field "tags" length greater than 2
Data Types: array, object, string
length less than
Fewer than N elements.
Field "errors" length less than 1
Field "description" length less than 500
Data Types: array, object, string
Range Operators
between
Value within range (inclusive).
Status Code between 200 and 299
Field "age" between 18 and 65
Response time between 100 and 500
Data Types: number
not between
Value outside range.
Status Code not between 400 and 599
Field "temperature" not between 0 and 100
Data Types: number
Array-Specific Operators
contains element
Array contains specific value.
Field "tags" contains element "important"
Field "roles" contains element "admin"
Data Types: array
does not contain element
Array does not contain value.
Field "tags" does not contain element "spam"
Data Types: array
all elements match
Every array element matches condition.
Field "prices[*]" all elements greater than 0
Field "emails[*]" all elements contains "@"
Data Types: array
any element matches
At least one array element matches condition.
Field "statuses[*]" any element equals "active"
Data Types: array
Special Operators
matches schema
Response matches JSON Schema.
Response body matches schema {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {"type": "number"},
"name": {"type": "string"}
}
}
Data Types: object, array
Status Code Operators
All comparison operators work with status codes:
Status Code equals 200
Status Code not equals 500
Status Code greater than or equal 200
Status Code less than 300
Status Code between 200 and 299
Header Operators
All string operators work with headers:
Header "Content-Type" equals "application/json"
Header "Content-Type" contains "json"
Header "Authorization" starts with "Bearer"
Header "Set-Cookie" exists
Response Time Operators
Numeric operators for performance:
Response time less than 500
Response time greater than 100
Response time between 100 and 500
Units: Milliseconds
Best Practices
Choose the Right Operator
- Exact matches: Use
equals - Partial matches: Use
contains - Ranges: Use
betweenorgreater/less than - Existence: Use
existsoris not null - Types: Use
is typefor validation
Data Types
Match operator to data type:
- Numeric comparisons for numbers only
- String operators for strings only
- Collection operators for arrays/objects
Performance
equalsis fastest- Regex is slowest
- Use simplest operator that works
Readability
- Use descriptive field names
- Combine multiple simple assertions
- Add comments for complex logic
Common Patterns
Successful Response
Status Code equals 200
Response time less than 500
Header "Content-Type" contains "json"
Field "status" equals "success"
Resource Created
Status Code equals 201
Header "Location" exists
Field "id" exists
Field "id" is type "number"
Error Response
Status Code between 400 and 499
Field "error" exists
Field "error.message" is type "string"
Field "error.code" is type "string"
Pagination
Field "results" is type "array"
Field "results" is not empty
Field "page" is type "number"
Field "page" greater than 0
Field "totalPages" greater than or equal {{page}}