<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>k6-testing on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/</link><description>Recent content in k6-testing on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/jslib/testing/index.xml" rel="self" type="application/rss+xml"/><item><title>expect()</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/</guid><content><![CDATA[&lt;h1 id=&#34;expect&#34;&gt;expect()&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;expect()&lt;/code&gt; function is the main entry point for creating assertions in the k6 testing library. It provides an intuitive API for both retrying and non-retrying assertions.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;!-- eslint-skip --&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;expect(actual);
expect(actual, message);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&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;actual&lt;/td&gt;
              &lt;td&gt;any&lt;/td&gt;
              &lt;td&gt;The value to test against&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;message&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;Optional custom error message&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&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;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;Expectation&lt;/td&gt;
              &lt;td&gt;An expectation object with assertion methods&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;description&#34;&gt;Description&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;expect()&lt;/code&gt; function wraps a value and returns an expectation object that provides assertion methods. The expectation object supports both retrying (that are asynchronous, and automatically retry until they pass or timeout) and non-retrying assertions (that are synchronous and evaluate immediately).&lt;/p&gt;
&lt;h3 id=&#34;non-retrying-assertions&#34;&gt;Non-retrying assertions&lt;/h3&gt;
&lt;p&gt;Standard assertions evaluate immediately and do not retry:&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

expect(42).toBe(42);
expect([1, 2, 3]).toContain(2);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;retrying-assertions&#34;&gt;Retrying Assertions&lt;/h3&gt;
&lt;p&gt;Retrying assertions automatically retry until they pass or timeout. These are particularly useful for browser testing where elements may not be immediately available:&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 { browser } from &amp;#39;k6/experimental/browser&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  }
};

export default async function () {
  const page = browser.newPage();
  await page.goto(&amp;#39;https://test.k6.io&amp;#39;);

  // Auto-retrying assertions
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toBeVisible();
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toHaveText(&amp;#39;Welcome to the k6 test site&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;negation&#34;&gt;Negation&lt;/h3&gt;
&lt;p&gt;All assertions can be negated using the &lt;code&gt;.not&lt;/code&gt; property:&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

expect(42).not.toBe(43);
expect(&amp;#39;hello&amp;#39;).not.toContain(&amp;#39;world&amp;#39;);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;soft-assertions&#34;&gt;Soft Assertions&lt;/h3&gt;
&lt;p&gt;By default, failed assertions will terminate the test execution. Soft assertions, on the other hand, don&amp;rsquo;t terminate the test execution when they fail, but mark the test as failed, leading k6 to eventually exit with code &lt;code&gt;110&lt;/code&gt;.&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 exec from &amp;#39;k6/execution&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export const options = {
  vus: 2,
  iterations: 10,
};

export default function () {
  // Iteration 3 will mark the test as failed, but the test execution
  // will keep going until its end condition, and eventually exit with
  // code 110.
  if (exec.scenario.iterationInInstance === 3) {
    expect.soft(false).toBeTruthy();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that soft assertions can be 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/configure/&#34;&gt;configured&lt;/a&gt; to throw an exception (and effectively failing the iteration where it happens) instead.&lt;/p&gt;
&lt;!-- eslint-skip --&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Configure soft mode globally
expect.configure({ softMode: &amp;#39;continue&amp;#39; });

export default function () {
  // These assertions will not stop test execution on failure
  expect.soft(response.status).toBe(200);
  expect.soft(response.json()).toHaveProperty(&amp;#39;data&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;api-testing&#34;&gt;API Testing&lt;/h3&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 http from &amp;#39;k6/http&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export default function () {
  const response = http.get(&amp;#39;https://test-api.k6.io/public/crocodiles/1/&amp;#39;);
  const data = response.json();

  // Basic assertions
  expect(response.status).toBe(200);
  expect(response.headers[&amp;#39;Content-Type&amp;#39;]).toContain(&amp;#39;application/json&amp;#39;);

  // Object assertions
  expect(data).toHaveProperty(&amp;#39;id&amp;#39;);
  expect(data.name).toBeDefined();
  expect(data.age).toBeGreaterThan(0);

  // With custom error message
  expect(data.status, &amp;#39;Crocodile should be alive&amp;#39;).toBe(&amp;#39;alive&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;browser-testing&#34;&gt;Browser Testing&lt;/h3&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 { browser } from &amp;#39;k6/experimental/browser&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export default async function () {
  const page = browser.newPage();

  await page.goto(&amp;#39;https://test.k6.io/my_messages.php&amp;#39;);

  // Form interaction with assertions
  await expect(page.locator(&amp;#39;#username&amp;#39;)).toBeVisible();
  await page.locator(&amp;#39;#username&amp;#39;).fill(&amp;#39;admin&amp;#39;);
  await expect(page.locator(&amp;#39;#username&amp;#39;)).toHaveValue(&amp;#39;admin&amp;#39;);

  await page.locator(&amp;#39;#password&amp;#39;).fill(&amp;#39;123&amp;#39;);
  await page.locator(&amp;#39;input[type=&amp;#34;submit&amp;#34;]&amp;#39;).click();

  // Verify navigation
  await expect(page.locator(&amp;#39;h2&amp;#39;)).toContainText(&amp;#39;Welcome, admin!&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;assertion-methods&#34;&gt;Assertion methods&lt;/h2&gt;
&lt;h3 id=&#34;non-retrying-assertions-1&#34;&gt;Non-Retrying Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobe/&#34;&gt;toBe(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Exact equality using Object.is()&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobecloseto/&#34;&gt;toBeCloseTo(expected, precision?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Floating point comparison&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobedefined/&#34;&gt;toBeDefined()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is not undefined&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobefalsy/&#34;&gt;toBeFalsy()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is falsy&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthan/&#34;&gt;toBeGreaterThan(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Greater than comparison&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthanorequal/&#34;&gt;toBeGreaterThanOrEqual(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Greater than or equal comparison&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobeinstanceof/&#34;&gt;toBeInstanceOf(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is an instance of a class&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobelessthan/&#34;&gt;toBeLessThan(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Less than comparison&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobelessthanorequal/&#34;&gt;toBeLessThanOrEqual(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Less than or equal comparison&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobenan/&#34;&gt;toBeNaN()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is NaN&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobenull/&#34;&gt;toBeNull()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is null&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobetruthy/&#34;&gt;toBeTruthy()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is truthy&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobeundefined/&#34;&gt;toBeUndefined()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is undefined&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tocontain/&#34;&gt;toContain(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Array/string contains value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tocontainorequal/&#34;&gt;toContainEqual(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Array or Set contains a similar element&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/toequal/&#34;&gt;toEqual(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Deep equality comparison&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tohavelength/&#34;&gt;toHaveLength(expected)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value has a expected length&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tohaveproperty/&#34;&gt;toHaveProperty(path, expected?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Property at provided path exists in the object and optionally checks that it is equal to expected&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;retrying-assertions-1&#34;&gt;Retrying Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobechecked/&#34;&gt;toBeChecked(options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Checkbox is checked&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobedisabled/&#34;&gt;toBeDisabled(options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is disabled&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeeditable/&#34;&gt;toBeEditable(options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is editable&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeenabled/&#34;&gt;toBeEnabled(options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is enabled&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobehidden/&#34;&gt;toBeHidden(options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is hidden&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobevisible/&#34;&gt;toBeVisible(options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is visible&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tocontaintext/&#34;&gt;toContainText(text, options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element contains text&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohaveattribute/&#34;&gt;toHaveAttribute(attribute, value?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element attribute value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavetext/&#34;&gt;toHaveText(text, options?)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element text content&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavevalue/&#34;&gt;toHaveValue(value)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Input element value&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;]]></content><description>&lt;h1 id="expect">expect()&lt;/h1>
&lt;p>The &lt;code>expect()&lt;/code> function is the main entry point for creating assertions in the k6 testing library. It provides an intuitive API for both retrying and non-retrying assertions.&lt;/p></description></item><item><title>expect.configure()</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/configure/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/configure/</guid><content><![CDATA[&lt;h1 id=&#34;expectconfigure&#34;&gt;expect.configure()&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;expect.configure()&lt;/code&gt; method creates a new configured &lt;code&gt;expect&lt;/code&gt; instance with custom behavior for the k6 testing library, including timeouts, display options, and soft assertion behavior.&lt;/p&gt;
&lt;p&gt;This new instance can be used in place of the default expect function, and will apply the specified configuration to all assertions made with it.&lt;/p&gt;
&lt;p&gt;The imported &lt;code&gt;expect&lt;/code&gt; instance remains unchanged and continues to use the default configuration, allowing different assertion configurations to co-exist within a test.&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;!-- eslint-skip --&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;const configuredExpect = expect.configure(options);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;parameters&#34;&gt;Parameters&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;options&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;Configuration options object&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;options&#34;&gt;Options&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;Property&lt;/th&gt;
              &lt;th&gt;Type&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;timeout&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;5000&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Default timeout in milliseconds for retrying assertions&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;interval&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;100&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Polling interval in milliseconds for retrying assertions&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;colorize&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Enable colorized output in assertion messages&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;display&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&amp;quot;pretty&amp;quot;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Output format for assertion messages (&lt;code&gt;&amp;quot;pretty&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;inline&amp;quot;&lt;/code&gt;)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;softMode&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&amp;quot;fail&amp;quot;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Soft assertion behavior (&lt;code&gt;&amp;quot;fail&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;throw&amp;quot;&lt;/code&gt;)&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&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;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;Expect&lt;/td&gt;
              &lt;td&gt;A new expect instance with the specified configuration&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;timeout-configuration&#34;&gt;Timeout configuration&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;timeout&lt;/code&gt; option controls how long retrying assertions will wait for a condition to become true:&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create a configured expect instance with longer timeout for slow-loading elements
const slowExpect = expect.configure({
  timeout: 10000, // 10 seconds
  interval: 500, // Check every 500ms
});&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;display-options&#34;&gt;Display Options&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;display&lt;/code&gt; and &lt;code&gt;colorize&lt;/code&gt; options control how assertion failures are reported:&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create expect instance with inline output and no colors
const inlineExpect = expect.configure({
  display: &amp;#39;inline&amp;#39;,
  colorize: false,
});&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;soft-assertion-mode&#34;&gt;Soft Assertion Mode&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;softMode&lt;/code&gt; option controls whether failed assertions stop test execution:&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// The default behavior of soft assertions is mark the test as failed, the `softMode` option
// allows to configure soft assertions to throw an exception and fail the current iteration instead.
const softExpect = expect.configure({
  softMode: &amp;#39;throw&amp;#39;,
});&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;environment-variables&#34;&gt;Environment Variables&lt;/h2&gt;
&lt;p&gt;Configuration options can also be set using environment variables:&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;Environment Variable&lt;/th&gt;
              &lt;th&gt;Option&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;&lt;code&gt;K6_TESTING_TIMEOUT&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;timeout&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Default timeout in milliseconds&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;K6_TESTING_INTERVAL&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;interval&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Polling interval in milliseconds&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;K6_TESTING_COLORIZE&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;colorize&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Enable colored output (&lt;code&gt;true&lt;/code&gt;/&lt;code&gt;false&lt;/code&gt;)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;K6_TESTING_DISPLAY&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;display&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Output format (&lt;code&gt;pretty&lt;/code&gt;/&lt;code&gt;inline&lt;/code&gt;)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;K6_TESTING_SOFT_MODE&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;softMode&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Soft assertion mode (&lt;code&gt;fail&lt;/code&gt;/&lt;code&gt;throw&lt;/code&gt;)&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;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;# Set environment variables
export K6_TESTING_TIMEOUT=10000
export K6_TESTING_SOFT_MODE=throw
k6 run test.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;basic-configuration&#34;&gt;Basic Configuration&lt;/h3&gt;
&lt;!-- eslint-skip --&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create a configured expect instance
const myExpect = expect.configure({
  timeout: 8000,
  interval: 200,
  colorize: true,
  display: &amp;#39;pretty&amp;#39;,
});

export default function () {
  // Use the configured instance
  myExpect(response.status).toBe(200);

  // Original expect instance still works with defaults
  expect(response.status).toBe(200);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;browser-testing-configuration&#34;&gt;Browser Testing Configuration&lt;/h3&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 { browser } from &amp;#39;k6/experimental/browser&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  }
};

// Create expect instance configured for browser testing with longer timeouts
const browserExpect = expect.configure({
  timeout: 15000, // Longer timeout for browser operations
  interval: 500, // Less frequent polling
});

export default async function () {
  const page = browser.newPage();
  await page.goto(&amp;#39;https://test.k6.io&amp;#39;);

  // Will wait up to 15 seconds for element to be visible
  await browserExpect(page.locator(&amp;#39;h1&amp;#39;)).toBeVisible();
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;cicd-configuration&#34;&gt;CI/CD Configuration&lt;/h3&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create expect instance configured for CI environment
const ciExpect = expect.configure({
  colorize: false, // Disable colors in CI logs
  display: &amp;#39;inline&amp;#39;, // inline output for CI
  timeout: 30000, // Longer timeout for CI environment
});&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;development-vs-production&#34;&gt;Development vs Production&lt;/h3&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Different configuration based on environment
const isDevelopment = __ENV.NODE_ENV === &amp;#39;development&amp;#39;;

const envExpect = expect.configure({
  timeout: isDevelopment ? 5000 : 15000,
  colorize: isDevelopment,
  display: isDevelopment ? &amp;#39;pretty&amp;#39; : &amp;#39;inline&amp;#39;,
  softMode: isDevelopment ? &amp;#39;continue&amp;#39; : &amp;#39;fail&amp;#39;,
});&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;multiple-configured-instances&#34;&gt;Multiple Configured Instances&lt;/h3&gt;
&lt;!-- eslint-skip --&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 { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export default function () {
  // Create specific expect instances for different scenarios
  const fastExpect = expect.configure({
    timeout: 1000,
    interval: 50,
  });

  const slowExpect = expect.configure({
    timeout: 30000,
    softMode: &amp;#39;continue&amp;#39;,
  });

  // Use appropriate instance for each test
  fastExpect(quickOperation()).toBe(true);
  slowExpect(slowOperation()).toBe(true);

  // Original expect instance still available
  expect(normalOperation()).toBe(true);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;soft-assertion-examples&#34;&gt;Soft Assertion Examples&lt;/h3&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 http from &amp;#39;k6/http&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create expect instance with soft assertions enabled
const softExpect = expect.configure({
  softMode: &amp;#39;continue&amp;#39;,
});

export default function () {
  const response = http.get(&amp;#39;https://test-api.k6.io/public/crocodiles/1/&amp;#39;);

  // These assertions will not stop test execution on failure
  softExpect(response.status).toBe(200);
  softExpect(response.json()).toHaveProperty(&amp;#39;name&amp;#39;);
  softExpect(response.json()).toHaveProperty(&amp;#39;age&amp;#39;);

  // Test continues even if assertions fail
  console.log(&amp;#39;Test completed&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="expectconfigure">expect.configure()&lt;/h1>
&lt;p>The &lt;code>expect.configure()&lt;/code> method creates a new configured &lt;code>expect&lt;/code> instance with custom behavior for the k6 testing library, including timeouts, display options, and soft assertion behavior.&lt;/p></description></item><item><title>Non-Retrying Assertions</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/</guid><content><![CDATA[&lt;h1 id=&#34;non-retrying-assertions&#34;&gt;Non-Retrying Assertions&lt;/h1&gt;
&lt;p&gt;Non-retrying assertions are synchronous assertions that allow to test any conditions, but do not auto-retry. They are ideal for testing static values, API responses, and any scenario where the expected condition should be true at the moment of evaluation.&lt;/p&gt;
&lt;p&gt;Non-retrying assertions differ from 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/&#34;&gt;retrying assertions&lt;/a&gt; in that they:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Evaluate immediately&lt;/strong&gt; - They check the condition once and return the result&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Are synchronous&lt;/strong&gt; - They don&amp;rsquo;t need to be awaited and return results immediately&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Have no timeout behavior&lt;/strong&gt; - They either pass or fail instantly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Are ideal for static content&lt;/strong&gt; - Perfect for testing values that don&amp;rsquo;t change over time&lt;/li&gt;
&lt;/ul&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 http from &amp;#39;k6/http&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export default function () {
  const response = http.get(&amp;#39;https://quickpizza.grafana.com/&amp;#39;);

  // Immediate assertions
  expect(response.status).toBe(200);
  expect(response.body).toBeDefined();
  expect(response.body).toBeTruthy();
  expect(typeof response.body).toBe(&amp;#39;string&amp;#39;);
  expect(response.body).toContain(&amp;#39;Pizza&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;when-to-use-non-retrying-assertions&#34;&gt;When to Use Non-Retrying Assertions&lt;/h2&gt;
&lt;p&gt;Non-retrying assertions are best suited for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;API response testing&lt;/strong&gt; - Checking status codes, response data, headers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static values&lt;/strong&gt; - Testing constants, configuration values, or computed results&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data validation&lt;/strong&gt; - Verifying object properties, array contents, or data types&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Known state verification&lt;/strong&gt; - Checking values that should be immediately available&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;non-retrying-assertions-methods&#34;&gt;Non-retrying assertions methods&lt;/h2&gt;
&lt;h3 id=&#34;equality-assertions&#34;&gt;Equality Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobe/&#34;&gt;toBe()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Exact equality using Object.is()&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/toequal/&#34;&gt;toEqual()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Deep equality comparison&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;truthiness-assertions&#34;&gt;Truthiness Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobetruthy/&#34;&gt;toBeTruthy()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is truthy&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobefalsy/&#34;&gt;toBeFalsy()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is falsy&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobedefined/&#34;&gt;toBeDefined()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is not undefined&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobeundefined/&#34;&gt;toBeUndefined()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is undefined&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobenull/&#34;&gt;toBeNull()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is null&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;comparison-assertions&#34;&gt;Comparison Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthan/&#34;&gt;toBeGreaterThan()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Numeric greater than&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthanorequal/&#34;&gt;toBeGreaterThanOrEqual()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Numeric greater than or equal&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobelessthan/&#34;&gt;toBeLessThan()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Numeric less than&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobelessthanorequal/&#34;&gt;toBeLessThanOrEqual()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Numeric less than or equal&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobecloseto/&#34;&gt;toBeCloseTo()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Floating point comparison&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;collection-assertions&#34;&gt;Collection Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tocontain/&#34;&gt;toContain()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Array/string contains value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tocontainequal/&#34;&gt;toContainEqual()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Array contains object with matching content&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tohavelength/&#34;&gt;toHaveLength()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Array/string has specific length&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;property-assertions&#34;&gt;Property Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tohaveproperty/&#34;&gt;toHaveProperty()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Object has specific property&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;type-assertions&#34;&gt;Type Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobeinstanceof/&#34;&gt;toBeInstanceOf()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Value is instance of class&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;common-patterns&#34;&gt;Common Patterns&lt;/h2&gt;
&lt;h3 id=&#34;api-response-validation&#34;&gt;API Response Validation&lt;/h3&gt;
&lt;!-- eslint-skip --&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;export default function () {
  const response = http.get(&amp;#39;https://quickpizza.grafana.com/&amp;#39;);

  // Response status and headers
  expect(response.status).toBe(200);
  expect(response.headers[&amp;#39;content-type&amp;#39;]).toContain(&amp;#39;text/html&amp;#39;);

  // Response data structure
  expect(response.body).toBeDefined();
  expect(response.body).toBeTruthy();
  expect(response.body).toContain(&amp;#39;pizza&amp;#39;);
  expect(response.body).toContain(&amp;#39;Pizza&amp;#39;);

  // Data types
  expect(typeof response.body).toBe(&amp;#39;string&amp;#39;);
  expect(response.body.length).toBeGreaterThan(0);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;data-validation&#34;&gt;Data Validation&lt;/h3&gt;
&lt;!-- eslint-skip --&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;export default function () {
  const userData = {
    name: &amp;#39;John Doe&amp;#39;,
    email: &amp;#39;john@example.com&amp;#39;,
    age: 30,
    hobbies: [&amp;#39;reading&amp;#39;, &amp;#39;gaming&amp;#39;],
    address: {
      city: &amp;#39;New York&amp;#39;,
      country: &amp;#39;USA&amp;#39;,
    },
  };

  // Object structure validation
  expect(userData).toHaveProperty(&amp;#39;name&amp;#39;);
  expect(userData).toHaveProperty(&amp;#39;address.city&amp;#39;);
  expect(userData.hobbies).toHaveLength(2);

  // Value validation
  expect(userData.name).toBeDefined();
  expect(userData.email).toContain(&amp;#39;@&amp;#39;);
  expect(userData.age).toBeGreaterThan(0);
  expect(userData.hobbies).toContain(&amp;#39;reading&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;configuration-testing&#34;&gt;Configuration Testing&lt;/h3&gt;
&lt;!-- eslint-skip --&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;export default function () {
  const config = {
    apiUrl: __ENV.API_URL || &amp;#39;https://api.example.com&amp;#39;,
    timeout: parseInt(__ENV.TIMEOUT || &amp;#39;5000&amp;#39;),
    retries: parseInt(__ENV.RETRIES || &amp;#39;3&amp;#39;),
    features: (__ENV.FEATURES || &amp;#39;feature1,feature2&amp;#39;).split(&amp;#39;,&amp;#39;),
  };

  // Configuration validation
  expect(config.apiUrl).toContain(&amp;#39;http&amp;#39;);
  expect(config.timeout).toBeGreaterThan(0);
  expect(config.retries).toBeGreaterThanOrEqual(0);
  expect(config.features).toContain(&amp;#39;feature1&amp;#39;);
  expect(config.features).toHaveLength(2);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;error-handling-patterns&#34;&gt;Error Handling Patterns&lt;/h2&gt;
&lt;h3 id=&#34;graceful-error-handling&#34;&gt;Graceful Error Handling&lt;/h3&gt;
&lt;!-- eslint-skip --&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;export default function () {
  const response = http.get(&amp;#39;https://quickpizza.grafana.com/&amp;#39;);

  // Check response status first
  if (response.status === 200) {
    expect(response.body).toBeDefined();
    expect(response.body).toBeTruthy();
    expect(response.body).toContain(&amp;#39;Pizza&amp;#39;);
  } else {
    // Handle error response
    expect(response.status).toBeGreaterThanOrEqual(400);
    expect(response.body).toContain(&amp;#39;error&amp;#39;);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobe/&#34;&gt;toBe()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/toequal/&#34;&gt;toEqual()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tocontain/&#34;&gt;toContain()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobetruthy/&#34;&gt;toBeTruthy()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobefalsy/&#34;&gt;toBeFalsy()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobedefined/&#34;&gt;toBeDefined()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthan/&#34;&gt;toBeGreaterThan()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobecloseto/&#34;&gt;toBeCloseTo()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tohavelength/&#34;&gt;toHaveLength()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tohaveproperty/&#34;&gt;toHaveProperty()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobegreaterthanorequal/&#34;&gt;toBeGreaterThanOrEqual()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobelessthan/&#34;&gt;toBeLessThan()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobenull/&#34;&gt;toBeNull()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobeundefined/&#34;&gt;toBeUndefined()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tocontainequal/&#34;&gt;toContainEqual()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobelessthanorequal/&#34;&gt;toBeLessThanOrEqual()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobeinstanceof/&#34;&gt;toBeInstanceOf()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/tobenan/&#34;&gt;toBeNaN()&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
]]></content><description>&lt;h1 id="non-retrying-assertions">Non-Retrying Assertions&lt;/h1>
&lt;p>Non-retrying assertions are synchronous assertions that allow to test any conditions, but do not auto-retry. They are ideal for testing static values, API responses, and any scenario where the expected condition should be true at the moment of evaluation.&lt;/p></description></item><item><title>Retrying Assertions</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/</guid><content><![CDATA[&lt;h1 id=&#34;retrying-assertions&#34;&gt;Retrying Assertions&lt;/h1&gt;
&lt;p&gt;Retrying assertions are asynchronous assertions that automatically retry until a condition becomes true or a timeout is reached. They are particularly useful for browser testing where elements may not be immediately available or when testing dynamic content that changes over time.&lt;/p&gt;
&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
&lt;p&gt;Retrying assertions differ from 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/&#34;&gt;non-retrying assertions&lt;/a&gt; in that they:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Automatically retry&lt;/strong&gt; - They continuously check the condition until it passes or times out&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Are asynchronous&lt;/strong&gt; - They return promises and must be &lt;code&gt;await&lt;/code&gt;-ed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Have configurable timeouts&lt;/strong&gt; - You can set custom timeout and polling intervals&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Are ideal for dynamic content&lt;/strong&gt; - Perfect for testing UI elements that appear/disappear or change over time&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;when-to-use-retrying-assertions&#34;&gt;When to Use Retrying Assertions&lt;/h2&gt;
&lt;p&gt;Retrying assertions are best suited for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Browser testing&lt;/strong&gt; - Checking element visibility, text content, or state changes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic content&lt;/strong&gt; - Testing content that loads asynchronously&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;User interactions&lt;/strong&gt; - Verifying UI changes after clicks, form submissions, etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loading states&lt;/strong&gt; - Waiting for spinners to disappear or content to appear&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;API polling&lt;/strong&gt; - Waiting for external systems to reach expected states&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;usage&#34;&gt;Usage&lt;/h2&gt;
&lt;p&gt;All retrying assertions must be awaited since they return promises:&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 { browser } from &amp;#39;k6/browser&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  }
};

export default async function () {
  const page = await browser.newPage();
  await page.goto(&amp;#39;https://quickpizza.grafana.com/&amp;#39;);

  // Wait for element to become visible
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toBeVisible();

  // Wait for specific text content
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toHaveText(&amp;#39;Looking to break out of your pizza routine?&amp;#39;);

  // Wait for element to be enabled
  await expect(page.locator(&amp;#39;button[name=&amp;#34;pizza-please&amp;#34;]&amp;#39;)).toBeEnabled();
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;
&lt;p&gt;You can configure timeout and polling behavior by creating a configured expect instance or per assertion:&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 { browser } from &amp;#39;k6/browser&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create configured expect instance
const slowExpect = expect.configure({
  timeout: 10000, // 10 seconds timeout
  interval: 200, // Check every 200ms
});

export default async function () {
  const page = await browser.newPage();
  await page.goto(&amp;#39;https://quickpizza.grafana.com/&amp;#39;);

  // Use configured timeout
  await slowExpect(page.locator(&amp;#39;h1&amp;#39;)).toBeVisible();

  // Override timeout for specific assertion
  await slowExpect(page.locator(&amp;#39;button[name=&amp;#34;pizza-please&amp;#34;]&amp;#39;)).toBeVisible({
    timeout: 30000,
  });

  // Original expect instance still available with defaults
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toBeVisible();
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;available-retrying-assertions&#34;&gt;Available Retrying Assertions&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;Method&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;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobevisible/&#34;&gt;toBeVisible()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is visible on the page&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobehidden/&#34;&gt;toBeHidden()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is hidden or not visible&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeenabled/&#34;&gt;toBeEnabled()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is enabled and interactive&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobedisabled/&#34;&gt;toBeDisabled()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is disabled&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobechecked/&#34;&gt;toBeChecked()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Checkbox or radio button is checked&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeeditable/&#34;&gt;toBeEditable()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is editable&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeempty/&#34;&gt;toBeEmpty()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element is empty&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavetext/&#34;&gt;toHaveText()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element has specific text content&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tocontaintext/&#34;&gt;toContainText()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element contains specific text&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavevalue/&#34;&gt;toHaveValue()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Input element has specific value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohaveattribute/&#34;&gt;toHaveAttribute()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Element has specific attribute value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavetitle/&#34;&gt;toHaveTitle()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Page has specific title&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;ul&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobechecked/&#34;&gt;toBeChecked()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobedisabled/&#34;&gt;toBeDisabled()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeeditable/&#34;&gt;toBeEditable()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeempty/&#34;&gt;toBeEmpty()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobehidden/&#34;&gt;toBeHidden()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobevisible/&#34;&gt;toBeVisible()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavetext/&#34;&gt;toHaveText()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tocontaintext/&#34;&gt;toContainText()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tobeenabled/&#34;&gt;toBeEnabled()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohaveattribute/&#34;&gt;toHaveAttribute()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavevalue/&#34;&gt;toHaveValue()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/tohavetitle/&#34;&gt;toHaveTitle()&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/retryconfig/&#34;&gt;RetryConfig&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
]]></content><description>&lt;h1 id="retrying-assertions">Retrying Assertions&lt;/h1>
&lt;p>Retrying assertions are asynchronous assertions that automatically retry until a condition becomes true or a timeout is reached. They are particularly useful for browser testing where elements may not be immediately available or when testing dynamic content that changes over time.&lt;/p></description></item></channel></rss>