Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: /docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobe.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobe/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
toBe()
The toBe() method asserts that the actual value is exactly equal to the expected value using Object.is() comparison.
Syntax
expect(actual).toBe(expected);
expect(actual).not.toBe(expected);Parameters
| Parameter | Type | Description |
|---|---|---|
| expected | any | The expected value |
Returns
| Type | Description |
|---|---|
| void | No return value |
Description
The toBe() method performs exact equality comparison using Object.is(). This means it checks for strict equality and handles special cases like NaN and -0 correctly.
Use toBe() when you want to assert that two values are the same reference or primitive value. For object comparison, use toEqual() instead.
Usage
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export default function () {
expect(42).toBe(42);
expect('hello').toBe('hello');
expect(true).toBe(true);
expect(null).toBe(null);
expect(undefined).toBe(undefined);
}Was this page helpful?
Related resources from Grafana Labs

