---
title: "toBe() | Grafana k6 documentation"
description: "Asserts that two values are exactly equal using Object.is() comparison"
---

# toBe()

The `toBe()` method asserts that the actual value is exactly equal to the expected value using `Object.is()` comparison.

## Syntax

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
expect(actual).toBe(expected);
expect(actual).not.toBe(expected);
```

## Parameters

Expand table

| Parameter | Type | Description        |
|-----------|------|--------------------|
| expected  | any  | The expected value |

## Returns

Expand table

| 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

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
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);
}
```
