Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/javascript-api/jslib/testing/non-retrying-assertions/tobenull.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/jslib/testing/non-retrying-assertions/tobenull/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
toBeNull()
The toBeNull() method asserts that a value is exactly null.
Syntax
expect(actual).toBeNull();
expect(actual).not.toBeNull();Returns
| Type | Description |
|---|---|
| void | No return value |
Description
The toBeNull() method checks if a value is exactly null. It only passes for the null value and fails for all other values, including undefined, false, 0, and empty strings.
Usage
import http from 'k6/http';
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export default function () {
const response = http.get('https://quickpizza.grafana.com/');
// Check for null values in response
const maybeNull = null;
if (maybeNull === null) {
expect(maybeNull).toBeNull();
}
// Check that required fields are not null
expect(response.body).not.toBeNull();
expect(response.status).not.toBeNull();
// Basic null checks
expect(null).toBeNull();
expect(undefined).not.toBeNull();
expect(false).not.toBeNull();
expect(0).not.toBeNull();
}Was this page helpful?
Related resources from Grafana Labs

