No results for

Powered byAlgolia
⚠️ This documentation is outdated. Please visit for the latest k6 documentation.📚

k6chaijs is a library to provide BDD assertions in k6 based on ChaiJS. You can use k6chaijs as an alternative to check and group.

With this library, you get the following:

  • BDD style of assertions for more expressive language
  • chainable assertions
  • more powerful assertions functions such as: deep, nested, ordered, etc.
  • automatic assertion messages
  • exception handling for better test stability


There's nothing to install. This library is hosted on jslib and can be imported in the k6 script directly.

import { describe, expect } from '';

Alternatively, you can use a copy of this file stored locally. The source code is available on GitHub.


The following example tests a hypothetical HTTP API that returns a JSON array of objects. Copy the following code, and save it as script.js:

import http from 'k6/http';
import { describe, expect } from '';
export default function testSuite() {
describe('Fetch a list of public crocodiles', () => {
const response = http.get('');
expect(response.status, 'response status').to.equal(200);
expect(response.json().length, 'number of crocs');

When you run this test with k6 run script.js, the output at the end of the test shows:

█ Fetch a list of public crocodiles
✓ expected response status to equal 200
✓ has valid json body
✓ expected number of crocs to be above 4

If you are familiar with k6, the result is the same as using check and group. Note that expect might add or extend the assertion message.


configOptions to change k6chaijs behaviour.
describeA wrapper of group that catches exceptions to allow continuing the test execution. It returns a boolean to indicate the success of all its k6chaijs assertions.
expectA wrapper of check that provides BDD style of assertions.


It's possible to extend the default functionality with Chai plugins. To use a plugin or build a Chai version with plugins, follow the instructions in this example.

Read more