No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.31. Go to the latest version

fail( [err] )

suggest edits

Immediately throw an error, aborting the current script iteration.

fail() is a simple convenience wrapper on top of JavaScript's throw(), because the latter cannot be used as [expr] || throw, which is a convenient way to write k6 test code.

err (optional)stringError message that gets printed to stderr.


Aborting the current script iteration if a check fails:

import http from 'k6/http';
import { check, fail } from 'k6';
export default function () {
let res = http.get('');
if (
!check(res, {
'status code MUST be 200': (res) => res.status == 200,
) {
fail('status code was *not* 200');