Apicat Docs
  1. Script examples
Apicat Docs
  • What is Apicat?
  • Send requests
    • Create requests
      • Request basics
      • Parameters and body
      • Request headers
      • Request settings
      • Dynamic values
      • HTTP/2
      • SOAP/WebService
    • Authentication and authorization
      • Overview
      • CA and client certificates
      • Authorization types supported by Apidog
      • Digest Auth
      • OAuth 1.0
      • OAuth 2.0
      • Hawk Authentication
      • Kerberos
      • NTLM
      • Akamai EdgeGrid
    • Response and cookies
      • Overview
      • API response in Apidog
      • Create and send cookies
      • Debug requests
    • Dynamic values Modules
      • Airline
      • Animal
      • Color
      • Commerce
      • Company
      • Database
      • Datatype
      • Date
      • Finance
      • Food
      • Git
      • Hacker
      • Helpers
      • Image
      • Internet
      • Location
      • Lorem
      • Music
      • Number
      • Person
      • Phone
      • Science
      • String
      • System
      • Vehicle
      • Word
  • Environments & variables
    • Overview
    • Using variables
    • Environments & services
  • Pre/Post processors
    • Overview
    • Assertion
    • Extract variable
    • Wait
    • Database operations
      • Overview
      • MySQL
      • MongoDB
      • Redis
      • Oracle Client
    • Using scripts
      • Overview
      • Pre processor scripts
      • Post processor scripts
      • Public scripts
      • Postman scripts reference
      • Calling other programming languages
      • Using JS libraries
      • Visualizing responses
      • Script examples
        • Assertion scripts
        • Using variables in scripts
        • Using scripts to modify request messages
        • Other examples
  • Best practices
    • How to handle API signatures
    • How to access OAuth 2.0 protected APIs
    • Apidog collaboration workflow
    • Managing authentication state in Apidog
  • Account & preferences
    • Account settings
    • Generate OpenAPI access token
    • Language settings
    • Hot keys
    • Network proxy configuration
    • Data backup
    • Updating Apidog
    • Deleting account
    • Experimental Features
  • References
    • API-Design First Approach
    • Apidog OpenAPI/Swagger Specificaiton Extensions
    • JSONPath
    • XPath
    • Regular Expressions
    • JSON Schema
    • CSV File Format
    • Install Java Environment
    • Runner deployment environment
    • Apidog flavored Markdown
  1. Script examples

Assertion scripts

Assertion scripts are code snippets that verify if conditions or assumptions in software are true, commonly used in testing to automate checks for expected behavior. They raise errors if assertions fail, ensuring software correctness.

Examples#

Assert whether the result returned by the request is correct:
Write the returned data to environment variables:
Check whether the response body includes a given string.

Syntax reference#

Check whether the response body is a given string#

Check the json output value#

Check whether the header is set as Content-Type#

Check whether the request response time is less than 200 milliseconds#

Check whether the HTTP status code is 200#

Check whether the HTTP status code name contains a string#

Check whether the POST request status code is correct.#

How to Use the Assertion Libraries#

Apidog has built-in ChaiJS as an assertion library. Below is an example of commonly used assertion test scripts. View the documentation, ChaiJS expect BDD library, for more examples.

Assert that the target string contains another string#

Assert that the target is strictly equal to (===) a value#

If the deep flag is on, the assert target is the value.
When you turn on the deep flag to use equal and property assertions, the flag will allow subsequent assertions to compare key-value pairs of objects recursively instead of comparing the objects themselves.

Assert that the depth is equal to a value, equivalent to deep.equal(value)#

Assert the current environment#

Assert a data structure#

TIP
1.
We recommend to use the .a method to check the data type of the template before making other assertions.
2.
Data types are case-sensitive.

Check if array is empty#

Check if an array is empty after using .a method#

Assert the key value of the target object#

Assert whether the target object contains the specified attribute#

TIP
1.
The target object must be an object, set, array, or map.
2.
If .keys is not preceded by .all or .any, it defaults to .all.
3.
Since only some data types of the target object can be used with the .keys method, we recommend asserting the data type with the .a method first.

Assert the length of the target object#

Assert the members of the target object (members)#

TIP
1.
By default, .members uses a strict comparison.
2.
The order of the members does not affect the result.

Asserts that the target object contains the specified item#

We recommend using .a method to determine the data type before using .include.
Example:
Modified at 2025-06-25 07:57:16
Previous
Visualizing responses
Next
Using variables in scripts
Built with