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/next/javascript-api/jslib/utils/check.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/jslib/utils/check/. 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.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
check( val, sets, [tags] )
The check function is a drop-in replacement for the built-in
check, with added support for async values. Any Promises will be awaited, and the result is reported once the operation has been completed.
| Parameter | Type | Description |
|---|---|---|
| val | any | Value to test. |
| sets | Record<string, any> | Tests (checks) to run on the value. Functions will be called. Promises will be awaited. |
| tags (optional) | Record<string, string> | Extra tags to attach to metrics emitted. |
Returns
| Type | Description | |
|---|---|---|
| Promise | boolean | true if all checks have succeeded, false otherwise. If any of the checked values was a Promise, the result is wrapped in a Promise. |
Examples
Using check() with async values.
import http from 'k6/http';
import { fail } from 'k6';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';
function waitFor(delay) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, delay);
});
}
export default async function () {
const res = http.get('https://quickpizza.grafana.com/');
const success = await check(res, {
'passing promise as a value': waitFor(1000),
'async function': async (res) => {
await waitFor(500);
return res.status === 200;
},
});
if (!success) {
fail('check did not succeed');
}
}For general usage of checks, refer to check(val, set, [tags]).
Was this page helpful?
Related resources from Grafana Labs

