- Declarative assertions - Simple assertions in the
assertblock - Test scripts - JavaScript test functions in the
testsblock
Declarative Assertions
Theassert block provides a simple, declarative syntax for common assertions:
Assertion Operators
Assertions use the format:expression: operator value
Comparison Operators
operator
Equal to (default if no operator specified)
operator
Not equal to
operator
Greater than
operator
Greater than or equal to
operator
Less than
operator
Less than or equal to
Collection Operators
operator
Value is in array
operator
Value is not in array
operator
String/array contains value
operator
String/array does not contain value
String Operators
operator
String starts with value
operator
String ends with value
operator
Matches regular expression
operator
Does not match regular expression
Size/Length Operators
operator
Array/string has exact length
operator
Value is between two numbers (inclusive)
State Operators (Unary)
These operators don’t require a value:operator
Value is empty (array, string, or object)
operator
Value is not empty
operator
Value is null
operator
Value is undefined
operator
Value is defined (not undefined)
operator
Value is truthy
operator
Value is falsy
Type Operators (Unary)
operator
Value is a JSON object
operator
Value is a number
operator
Value is a string
operator
Value is a boolean
operator
Value is an array
Assertion Examples
Test Scripts
For more complex validations, use thetests block with JavaScript:
Test Function
function
Defines a test caseParameters:
description(string) - Test descriptioncallback(function) - Test function (can be async)
Chai Assertions
Bruno includes the Chai assertion library with BDD-style assertions.Expect API
Theexpect function is the primary assertion method:
Assert API
Alternatively, use theassert style:
Chaining Assertions
Chain multiple assertions for better readability:Common Test Patterns
Status Code Validation
Response Body Validation
Array Validation
Header Validation
Response Time Validation
JWT Token Validation
Schema Validation
Combining Assertions and Tests
You can use both declarative assertions and test scripts together:Next Steps
Pre-request Scripts
Modify requests before sending
Post-response Scripts
Process responses and extract data