<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>k6chaijs on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/</link><description>Recent content in k6chaijs on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/index.xml" rel="self" type="application/rss+xml"/><item><title>config</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/config/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/config/</guid><content><![CDATA[&lt;h1 id=&#34;config&#34;&gt;config&lt;/h1&gt;
&lt;p&gt;Chai exposes a few options to change the library configuration.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Config option&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;truncateMsgThreshold&lt;/td&gt;
              &lt;td&gt;300&lt;/td&gt;
              &lt;td&gt;Check message length is truncated to this value.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;truncateVariableThreshold&lt;/td&gt;
              &lt;td&gt;100&lt;/td&gt;
              &lt;td&gt;Variables interpolated into check message are truncated to this length. It prevents mistakes when the check name is very large, especially when &lt;code&gt;aggregateChecks&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;aggregateChecks&lt;/td&gt;
              &lt;td&gt;true&lt;/td&gt;
              &lt;td&gt;The actual values are not interpolated into the check message. Disable for tests with 1 iteration.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;logFailures&lt;/td&gt;
              &lt;td&gt;false&lt;/td&gt;
              &lt;td&gt;When the check fails, debug messages are printed.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;
&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import chai, { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;

// 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(&amp;#39;Testing bad assertion.&amp;#39;, () =&amp;gt; {
    const response = http.get(&amp;#39;https://quickpizza.grafana.com&amp;#39;);

    expect(response.body).to.have.lengthOf.at.least(100);
  });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Resulting in:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;█ Testing bad assertion.
  ✓ expected &amp;#39;&amp;lt;!DOCTYPE html&amp;gt;\n&amp;lt;html lang=&amp;#34;en&amp;#34;&amp;gt;\n&amp;lt;hea...&amp;#39; to have property &amp;#39;length&amp;#39;
  ✓ expected &amp;#39;&amp;lt;!DOCTYPE html&amp;gt;\n&amp;lt;html lang=&amp;#34;en&amp;#34;&amp;gt;\n&amp;lt;hea...&amp;#39; to have a length at least 100 got 2611&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="config">config&lt;/h1>
&lt;p>Chai exposes a few options to change the library configuration.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Config option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>truncateMsgThreshold&lt;/td>
&lt;td>300&lt;/td>
&lt;td>Check message length is truncated to this value.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>truncateVariableThreshold&lt;/td>
&lt;td>100&lt;/td>
&lt;td>Variables interpolated into check message are truncated to this length. It prevents mistakes when the check name is very large, especially when &lt;code>aggregateChecks&lt;/code> is &lt;code>false&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>aggregateChecks&lt;/td>
&lt;td>true&lt;/td>
&lt;td>The actual values are not interpolated into the check message. Disable for tests with 1 iteration.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>logFailures&lt;/td>
&lt;td>false&lt;/td>
&lt;td>When the check fails, debug messages are printed.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import http from &amp;#39;k6/http&amp;#39;;
import chai, { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;
// 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(&amp;#39;Testing bad assertion.&amp;#39;, () =&amp;gt; {
const response = http.get(&amp;#39;https://quickpizza.grafana.com&amp;#39;);
expect(response.body).to.have.lengthOf.at.least(100);
});
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Resulting in:&lt;/p></description></item><item><title>describe( name, function )</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/describe/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/describe/</guid><content><![CDATA[&lt;h1 id=&#34;describe-name-function-&#34;&gt;describe( name, function )&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;describe&lt;/code&gt; is a wrapper of 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/group/&#34;&gt;group&lt;/a&gt; that adds the ability to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/error-handling/&#34;&gt;Catch exceptions&lt;/a&gt; to allow continuing the execution outside of the &lt;code&gt;describe&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Returns a boolean to indicate the success of all its &lt;code&gt;k6chaijs&lt;/code&gt; assertions.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;

export default function testSuite() {
  const success1 = describe(&amp;#39;Basic test&amp;#39;, () =&amp;gt; {
    expect(1, &amp;#39;number one&amp;#39;).to.equal(1);
  });
  console.log(success1); // true

  const success2 = describe(&amp;#39;Another test&amp;#39;, () =&amp;gt; {
    throw &amp;#39;Something entirely unexpected happened&amp;#39;;
  });
  console.log(success2); // false

  const success3 = describe(&amp;#39;Yet another test&amp;#39;, () =&amp;gt; {
    expect(false, &amp;#39;my vaule&amp;#39;).to.be.true();
  });
  console.log(success3); // false
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

     █ Basic test
       ✓ expected number one to equal 1

     █ Another test
       ✗ Exception raised &amp;#34;Something entirely unexpected happened&amp;#34;
        ↳  0% — ✓ 0 / ✗ 1

     █ Yet another test
       ✗ expected my vaule to be true
        ↳  0% — ✓ 0 / ✗ 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;name&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;Test case name. The test case name should be unique. Otherwise, the test case will be grouped.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;function&lt;/td&gt;
              &lt;td&gt;function&lt;/td&gt;
              &lt;td&gt;The test case function to be executed&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;bool&lt;/td&gt;
              &lt;td&gt;Returns true when all &lt;code&gt;expect&lt;/code&gt; conditions within the &lt;code&gt;describe()&lt;/code&gt; body were successful, and no unhandled exceptions were raised, otherwise false.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;chaining-describe-blocks&#34;&gt;Chaining describe() blocks&lt;/h2&gt;
&lt;p&gt;If you want to skip the execution of the following &lt;code&gt;describe&lt;/code&gt; blocks, consider chaining them using &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; as shown below.&lt;/p&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;

export default function testSuite() {
  describe(&amp;#39;Basic test&amp;#39;, () =&amp;gt; {
    expect(1, &amp;#39;number one&amp;#39;).to.equal(1);
  }) &amp;amp;&amp;amp;
    describe(&amp;#39;Another test&amp;#39;, () =&amp;gt; {
      throw &amp;#39;Something entirely unexpected happened&amp;#39;;
    }) &amp;amp;&amp;amp;
    describe(&amp;#39;Yet another test&amp;#39;, () =&amp;gt; {
      // the will not be executed because the prior block returned `false`
      expect(false, &amp;#39;my vaule&amp;#39;).to.be.true();
    });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="describe-name-function-">describe( name, function )&lt;/h1>
&lt;p>&lt;code>describe&lt;/code> is a wrapper of
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/group/">group&lt;/a> that adds the ability to:&lt;/p>
&lt;ul>
&lt;li>
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/error-handling/">Catch exceptions&lt;/a> to allow continuing the execution outside of the &lt;code>describe&lt;/code> function.&lt;/li>
&lt;li>Returns a boolean to indicate the success of all its &lt;code>k6chaijs&lt;/code> assertions.&lt;/li>
&lt;/ul>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;
export default function testSuite() {
const success1 = describe(&amp;#39;Basic test&amp;#39;, () =&amp;gt; {
expect(1, &amp;#39;number one&amp;#39;).to.equal(1);
});
console.log(success1); // true
const success2 = describe(&amp;#39;Another test&amp;#39;, () =&amp;gt; {
throw &amp;#39;Something entirely unexpected happened&amp;#39;;
});
console.log(success2); // false
const success3 = describe(&amp;#39;Yet another test&amp;#39;, () =&amp;gt; {
expect(false, &amp;#39;my vaule&amp;#39;).to.be.true();
});
console.log(success3); // false
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">Bash&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-bash">default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1 iters, 1 per VU
█ Basic test
✓ expected number one to equal 1
█ Another test
✗ Exception raised &amp;#34;Something entirely unexpected happened&amp;#34;
↳ 0% — ✓ 0 / ✗ 1
█ Yet another test
✗ expected my vaule to be true
↳ 0% — ✓ 0 / ✗ 1&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;h2 id="api">API&lt;/h2>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>name&lt;/td>
&lt;td>string&lt;/td>
&lt;td>Test case name. The test case name should be unique. Otherwise, the test case will be grouped.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>function&lt;/td>
&lt;td>function&lt;/td>
&lt;td>The test case function to be executed&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>bool&lt;/td>
&lt;td>Returns true when all &lt;code>expect&lt;/code> conditions within the &lt;code>describe()&lt;/code> body were successful, and no unhandled exceptions were raised, otherwise false.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h2 id="chaining-describe-blocks">Chaining describe() blocks&lt;/h2>
&lt;p>If you want to skip the execution of the following &lt;code>describe&lt;/code> blocks, consider chaining them using &lt;code>&amp;amp;&amp;amp;&lt;/code> as shown below.&lt;/p></description></item><item><title>expect()</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/expect/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/expect/</guid><content><![CDATA[&lt;h1 id=&#34;expect&#34;&gt;expect()&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;expect&lt;/code&gt; is a wrapper of 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;check&lt;/a&gt; to provide BDD style of assertions in k6. It implements the &lt;a href=&#34;https://www.chaijs.com/api/bdd/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Chai Expect API&lt;/a&gt;:&lt;/p&gt;
&lt;Glossary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_not&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;not&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_deep&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;deep&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_nested&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;nested&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_own&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;own&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_ordered&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ordered&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_any&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;any&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_all&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;all&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_a&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;a&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_include&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;include&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_ok&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ok&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_true&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;true&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_false&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;false&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_null&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;null&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_undefined&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;undefined&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_nan&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;NaN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_exist&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;exist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_empty&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;empty&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_arguments&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;arguments&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_equal&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;equal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_eql&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;eql&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_above&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;above&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_least&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;least&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_below&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;below&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_most&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;most&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_within&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;within&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_instanceof&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;instanceof&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_property&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;property&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_ownpropertydescriptor&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ownPropertyDescriptor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_lengthOf&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;lengthOf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_match&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;match&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_string&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;string&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_keys&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;keys&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_throw&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;throw&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_respondto&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;respondTo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_itself&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;itself&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_satisfy&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;satisfy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_closeto&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;closeTo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_members&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;members&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_oneOf&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;oneOf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_change&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;change&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_increase&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;increase&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_decrease&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;decrease&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_by&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;by&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_extensible&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;extensible&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_sealed&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;sealed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_frozen&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;frozen&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.chaijs.com/api/bdd/#method_finite&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;finite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/Glossary&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;

export default function () {
  describe(&amp;#39;Basic test&amp;#39;, () =&amp;gt; {
    expect({ a: 1 }).to.not.have.property(&amp;#39;b&amp;#39;);
    expect(2).to.equal(2);
    expect({ a: 1 }).to.deep.equal({ a: 1 });
    expect({ a: { b: [&amp;#39;x&amp;#39;, &amp;#39;y&amp;#39;] } }).to.have.nested.property(&amp;#39;a.b[1]&amp;#39;);
    expect({ a: 1 }).to.have.own.property(&amp;#39;a&amp;#39;);
    expect([1, 2]).to.have.ordered.members([1, 2]).but.not.have.ordered.members([2, 1]);
    expect({ a: 1, b: 2 }).to.not.have.any.keys(&amp;#39;c&amp;#39;, &amp;#39;d&amp;#39;);
    expect({ a: 1, b: 2 }).to.have.all.keys(&amp;#39;a&amp;#39;, &amp;#39;b&amp;#39;);
    expect(&amp;#39;foo&amp;#39;).to.be.a(&amp;#39;string&amp;#39;);
    expect([1, 2, 3]).to.be.an(&amp;#39;array&amp;#39;).that.includes(2);
    expect(&amp;#39;foobar&amp;#39;).to.include(&amp;#39;foo&amp;#39;);
    expect(1).to.equal(1);
    expect(true).to.be.true;
    expect(false).to.be.false;
    expect(null).to.be.null;
    expect(undefined).to.be.undefined;
    expect(NaN).to.be.NaN;
    expect(1).to.equal(1);
    expect([]).to.be.empty;
    expect({}).not.to.be.arguments;
    expect(1).to.equal(1);
    expect({ a: 1 }).to.eql({ a: 1 }).but.not.equal({ a: 1 });
    expect(&amp;#39;foo&amp;#39;).to.have.lengthOf(3);
    expect(2).to.equal(2);
    expect(1).to.equal(1);
    expect(2).to.be.at.most(3);
    expect(2).to.equal(2);
    expect({ a: 1 }).to.not.be.an.instanceof(Array);
    expect({ a: 1 }).to.have.property(&amp;#39;a&amp;#39;);
    expect([1, 2, 3]).to.have.lengthOf(3);
    expect(&amp;#39;foobar&amp;#39;).to.match(/^foo/);
    expect(&amp;#39;foobar&amp;#39;).to.have.string(&amp;#39;bar&amp;#39;);
    expect({ a: 1, b: 2 }).to.have.all.keys(&amp;#39;a&amp;#39;, &amp;#39;b&amp;#39;);
    const badFn = function () {
      throw new TypeError(&amp;#39;Illegal salmon!&amp;#39;);
    };
    expect(badFn).to.throw();
    expect(1).to.satisfy(function (num) {
      return num &amp;gt; 0;
    });
    expect(1.5).to.equal(1.5);
    expect([1, 2, 3]).to.have.members([2, 1, 3]);
    expect(&amp;#39;Today is sunny&amp;#39;).to.contain.oneOf([&amp;#39;sunny&amp;#39;, &amp;#39;cloudy&amp;#39;]);
    expect({ a: 1 }).to.be.extensible;
    expect(1).to.be.finite;
  });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When you run this test with &lt;code&gt;k6 run script.js&lt;/code&gt;, the output at the end of the test shows:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

     █ Basic test

       ✓ expected ${this} to not have property &amp;#39;b&amp;#39;
       ✓ expected ${this} to equal 2
       ✓ expected ${this} to deeply equal { a: 1 }
       ✓ expected ${this} to have nested property &amp;#39;a.b[1]&amp;#39;
       ✓ expected ${this} to have own property &amp;#39;a&amp;#39;
       ✓ expected ${this} to be an array
       ✓ expected ${this} to have the same ordered members as [ 1, 2 ]
       ✓ expected ${this} to not have the same ordered members as [ 2, 1 ]
       ✓ expected ${this} to not have keys &amp;#39;c&amp;#39;, or &amp;#39;d&amp;#39;
       ✓ expected ${this} to have keys &amp;#39;a&amp;#39;, and &amp;#39;b&amp;#39;
       ✓ expected ${this} to be a string
       ✓ expected ${this} to include 2
       ✓ expected ${this} to include &amp;#39;foo&amp;#39;
       ✓ expected ${this} to equal 1
       ✓ expected ${this} to be true
       ✓ expected ${this} to be false
       ✓ expected ${this} to be null
       ✓ expected ${this} to be undefined
       ✓ expected ${this} to be NaN
       ✓ expected ${this} to be empty
       ✓ expected ${this} to not be arguments
       ✓ expected ${this} to not equal { a: 1 }
       ✓ expected ${this} to have property &amp;#39;length&amp;#39;
       ✓ expected ${this} to have a length of 3 got ${actual}
       ✓ expected ${this} to be at most 3
       ✓ expected ${this} to not be an instance of Array
       ✓ expected ${this} to have property &amp;#39;a&amp;#39;
       ✓ expected ${this} to match /^foo/
       ✓ expected ${this} to contain &amp;#39;bar&amp;#39;
       ✓ expected ${this} to be a function
       ✓ expected ${this} to throw an error
       ✓ expected ${this} to satisfy [Function]
       ✓ expected ${this} to equal 1.5
       ✓ expected ${this} to have the same members as [ 2, 1, 3 ]
       ✓ expected ${this} to contain one of [ &amp;#39;sunny&amp;#39;, &amp;#39;cloudy&amp;#39; ]
       ✓ expected ${this} to be extensible
       ✓ expected ${this} to be a finite number&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="expect">expect()&lt;/h1>
&lt;p>&lt;code>expect&lt;/code> is a wrapper of
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/check/">check&lt;/a> to provide BDD style of assertions in k6. It implements the &lt;a href="https://www.chaijs.com/api/bdd/" target="_blank" rel="noopener noreferrer">Chai Expect API&lt;/a>:&lt;/p>
&lt;Glossary>
&lt;ul>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_not" target="_blank" rel="noopener noreferrer">not&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_deep" target="_blank" rel="noopener noreferrer">deep&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_nested" target="_blank" rel="noopener noreferrer">nested&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_own" target="_blank" rel="noopener noreferrer">own&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_ordered" target="_blank" rel="noopener noreferrer">ordered&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_any" target="_blank" rel="noopener noreferrer">any&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_all" target="_blank" rel="noopener noreferrer">all&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_a" target="_blank" rel="noopener noreferrer">a&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_include" target="_blank" rel="noopener noreferrer">include&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_ok" target="_blank" rel="noopener noreferrer">ok&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_true" target="_blank" rel="noopener noreferrer">true&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_false" target="_blank" rel="noopener noreferrer">false&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_null" target="_blank" rel="noopener noreferrer">null&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_undefined" target="_blank" rel="noopener noreferrer">undefined&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_nan" target="_blank" rel="noopener noreferrer">NaN&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_exist" target="_blank" rel="noopener noreferrer">exist&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_empty" target="_blank" rel="noopener noreferrer">empty&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_arguments" target="_blank" rel="noopener noreferrer">arguments&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_equal" target="_blank" rel="noopener noreferrer">equal&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_eql" target="_blank" rel="noopener noreferrer">eql&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_above" target="_blank" rel="noopener noreferrer">above&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_least" target="_blank" rel="noopener noreferrer">least&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_below" target="_blank" rel="noopener noreferrer">below&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_most" target="_blank" rel="noopener noreferrer">most&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_within" target="_blank" rel="noopener noreferrer">within&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_instanceof" target="_blank" rel="noopener noreferrer">instanceof&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_property" target="_blank" rel="noopener noreferrer">property&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_ownpropertydescriptor" target="_blank" rel="noopener noreferrer">ownPropertyDescriptor&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_lengthOf" target="_blank" rel="noopener noreferrer">lengthOf&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_match" target="_blank" rel="noopener noreferrer">match&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_string" target="_blank" rel="noopener noreferrer">string&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_keys" target="_blank" rel="noopener noreferrer">keys&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_throw" target="_blank" rel="noopener noreferrer">throw&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_respondto" target="_blank" rel="noopener noreferrer">respondTo&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_itself" target="_blank" rel="noopener noreferrer">itself&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_satisfy" target="_blank" rel="noopener noreferrer">satisfy&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_closeto" target="_blank" rel="noopener noreferrer">closeTo&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_members" target="_blank" rel="noopener noreferrer">members&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_oneOf" target="_blank" rel="noopener noreferrer">oneOf&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_change" target="_blank" rel="noopener noreferrer">change&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_increase" target="_blank" rel="noopener noreferrer">increase&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_decrease" target="_blank" rel="noopener noreferrer">decrease&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_by" target="_blank" rel="noopener noreferrer">by&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_extensible" target="_blank" rel="noopener noreferrer">extensible&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_sealed" target="_blank" rel="noopener noreferrer">sealed&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_frozen" target="_blank" rel="noopener noreferrer">frozen&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.chaijs.com/api/bdd/#method_finite" target="_blank" rel="noopener noreferrer">finite&lt;/a>&lt;/li>
&lt;/ul>
&lt;/Glossary>
&lt;!-- eslint-skip -->
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import http from &amp;#39;k6/http&amp;#39;;
import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;
export default function () {
describe(&amp;#39;Basic test&amp;#39;, () =&amp;gt; {
expect({ a: 1 }).to.not.have.property(&amp;#39;b&amp;#39;);
expect(2).to.equal(2);
expect({ a: 1 }).to.deep.equal({ a: 1 });
expect({ a: { b: [&amp;#39;x&amp;#39;, &amp;#39;y&amp;#39;] } }).to.have.nested.property(&amp;#39;a.b[1]&amp;#39;);
expect({ a: 1 }).to.have.own.property(&amp;#39;a&amp;#39;);
expect([1, 2]).to.have.ordered.members([1, 2]).but.not.have.ordered.members([2, 1]);
expect({ a: 1, b: 2 }).to.not.have.any.keys(&amp;#39;c&amp;#39;, &amp;#39;d&amp;#39;);
expect({ a: 1, b: 2 }).to.have.all.keys(&amp;#39;a&amp;#39;, &amp;#39;b&amp;#39;);
expect(&amp;#39;foo&amp;#39;).to.be.a(&amp;#39;string&amp;#39;);
expect([1, 2, 3]).to.be.an(&amp;#39;array&amp;#39;).that.includes(2);
expect(&amp;#39;foobar&amp;#39;).to.include(&amp;#39;foo&amp;#39;);
expect(1).to.equal(1);
expect(true).to.be.true;
expect(false).to.be.false;
expect(null).to.be.null;
expect(undefined).to.be.undefined;
expect(NaN).to.be.NaN;
expect(1).to.equal(1);
expect([]).to.be.empty;
expect({}).not.to.be.arguments;
expect(1).to.equal(1);
expect({ a: 1 }).to.eql({ a: 1 }).but.not.equal({ a: 1 });
expect(&amp;#39;foo&amp;#39;).to.have.lengthOf(3);
expect(2).to.equal(2);
expect(1).to.equal(1);
expect(2).to.be.at.most(3);
expect(2).to.equal(2);
expect({ a: 1 }).to.not.be.an.instanceof(Array);
expect({ a: 1 }).to.have.property(&amp;#39;a&amp;#39;);
expect([1, 2, 3]).to.have.lengthOf(3);
expect(&amp;#39;foobar&amp;#39;).to.match(/^foo/);
expect(&amp;#39;foobar&amp;#39;).to.have.string(&amp;#39;bar&amp;#39;);
expect({ a: 1, b: 2 }).to.have.all.keys(&amp;#39;a&amp;#39;, &amp;#39;b&amp;#39;);
const badFn = function () {
throw new TypeError(&amp;#39;Illegal salmon!&amp;#39;);
};
expect(badFn).to.throw();
expect(1).to.satisfy(function (num) {
return num &amp;gt; 0;
});
expect(1.5).to.equal(1.5);
expect([1, 2, 3]).to.have.members([2, 1, 3]);
expect(&amp;#39;Today is sunny&amp;#39;).to.contain.oneOf([&amp;#39;sunny&amp;#39;, &amp;#39;cloudy&amp;#39;]);
expect({ a: 1 }).to.be.extensible;
expect(1).to.be.finite;
});
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>When you run this test with &lt;code>k6 run script.js&lt;/code>, the output at the end of the test shows:&lt;/p></description></item><item><title>Error handling</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/error-handling/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/error-handling/</guid><content><![CDATA[&lt;h1 id=&#34;error-handling&#34;&gt;Error handling&lt;/h1&gt;
&lt;p&gt;When you execute a load test, your System Under Test (SUT) may often become over saturated and start responding with errors. In this case, you need to consider what the iteration execution should do:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;to embrace the system error and continue the execution of the scenario&lt;/li&gt;
&lt;li&gt;or to exit&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It&amp;rsquo;s not uncommon for performance testers to forget about these cases. We often write fragile test code that assumes our system&amp;rsquo;s response will always succeed and contain the expected data.&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { check, group } from &amp;#39;k6&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

export default function () {
  group(&amp;#39;Fetch a list of pizza names&amp;#39;, () =&amp;gt; {
    const res = http.get(&amp;#39;https://quickpizza.grafana.com/api/names&amp;#39;);
    check(res, {
      &amp;#39;is status 200&amp;#39;: (r) =&amp;gt; r.status === 200,
      &amp;#39;got more than 5 crocs&amp;#39;: (r) =&amp;gt; r.json().length &amp;gt; 5,
    });
    // ... continue test within the group...
  });

  group(&amp;#39;other group&amp;#39;, () =&amp;gt; {
    //...
  });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This code will work fine when the SUT returns correct responses. But, when the SUT starts to fail, &lt;code&gt;r.json().length&lt;/code&gt; will throw an exception:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;ERRO[0001] cannot parse json due to an error at line 1, character 2 , error: invalid character &amp;#39;&amp;lt;&amp;#39; looking for beginning of value
running at reflect.methodValueCall (native)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this case, k6 throws a JavaScript exception and &lt;strong&gt;exits the execution of the current iteration&lt;/strong&gt; but continues starting new iterations.&lt;/p&gt;
&lt;p&gt;This might not be ideal because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;system errors are propagated as exceptions that are not reported on the test results&lt;/li&gt;
&lt;li&gt;you might want to embrace these errors - as normal - and continue the execution&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It&amp;rsquo;s possible to rewrite this test to be less fragile, but it can make our test code longer and less readable.&lt;/p&gt;
&lt;h2 id=&#34;handling-exceptions&#34;&gt;Handling exceptions&lt;/h2&gt;
&lt;p&gt;Sometimes it&amp;rsquo;s hard to predict how a SUT might fail. For those cases, 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/describe/&#34;&gt;describe&lt;/a&gt; catches any internal exceptions and:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;records them as failed assertions&lt;/li&gt;
&lt;li&gt;continues the execution (outside of its &lt;code&gt;describe()&lt;/code&gt; function)&lt;/li&gt;
&lt;/ol&gt;
&lt;!-- md-k6:nofail --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;

export default function testSuite() {
  describe(&amp;#39;Test case against a Shaky SUT&amp;#39;, (t) =&amp;gt; {
    throw &amp;#39;Something entirely unexpected happened&amp;#39;;
  });

  // this test case will be executed because
  // the previous `describe` catched the exception
  describe(&amp;#39;Another test case&amp;#39;, (t) =&amp;gt; {
    expect(2).to.equal(2);
  });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;█ Test case against a Shaky SUT

  ✗ Exception raised &amp;#34;Something entirely unexpected happened&amp;#34;
  ↳  0% — ✓ 0 / ✗ 1

█ Another test case

  ✓ expected ${this} to equal 2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="error-handling">Error handling&lt;/h1>
&lt;p>When you execute a load test, your System Under Test (SUT) may often become over saturated and start responding with errors. In this case, you need to consider what the iteration execution should do:&lt;/p></description></item></channel></rss>