Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/v0.48.x/javascript-api/jslib/k6chaijs/config.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/v0.48.x/javascript-api/jslib/k6chaijs/config/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
config
Chai exposes a few options to change the library configuration.
| Config option | Default | Description |
|---|---|---|
| truncateMsgThreshold | 300 | Check message length is truncated to this value. |
| truncateVariableThreshold | 100 | Variables interpolated into check message are truncated to this length. It prevents mistakes when the check name is very large, especially when aggregateChecks is false. |
| aggregateChecks | true | The actual values are not interpolated into the check message. Disable for tests with 1 iteration. |
| logFailures | false | When the check fails, debug messages are printed. |
import http from 'k6/http';
import chai, { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';
// individual variables should be up to 20 chars after rendering.
chai.config.truncateVariableThreshold = 20;
// whole check() message must be below 300 chars.
chai.config.truncateMsgThreshold = 300;
// the variable values (resp.status) are inserted into the check message - useful for debugging or tests with 1 iteration
chai.config.aggregateChecks = false;
// when the check fails, WARN messages with variables are printed. Useful for debugging.
chai.config.logFailures = true;
export default function testSuite() {
describe('Testing bad assertion.', () => {
const response = http.get('https://test-api.k6.io/');
expect(response.body).to.have.lengthOf.at.least(500);
});
}The resulting
█ Testing bad assertion.
✓ expected '<!DOCTYPE html>\n<html lang="en">\n<hea...' to have property 'length'
✓ expected '<!DOCTYPE html>\n<html lang="en">\n<hea...' to have a length at least 500 got 15714Was this page helpful?
Related resources from Grafana Labs

