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/tobenan.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tobenan/. 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.
toBeNaN()
The toBeNaN() method asserts that a value is NaN (Not a Number).
Syntax
expect(actual).toBeNaN();
expect(actual).not.toBeNaN();Returns
| Type | Description |
|---|---|
| void | No return value |
Description
The toBeNaN() method checks if a value is exactly NaN using Number.isNaN(). It only passes for the NaN value and fails for all other values, including numbers, strings, and other falsy values.
Usage
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export default function () {
const formData = {
age: '25',
invalidNumber: 'not-a-number',
};
// Validate numeric conversions
expect(Number(formData.age)).not.toBeNaN();
expect(Number(formData.invalidNumber)).toBeNaN();
// Mathematical operations that result in NaN
expect(0 / 0).toBeNaN();
expect(Math.sqrt(-1)).toBeNaN();
expect(Infinity - Infinity).toBeNaN();
// Valid numbers are not NaN
expect(123).not.toBeNaN();
expect(Infinity).not.toBeNaN();
expect(1 / 0).not.toBeNaN(); // Infinity
}Was this page helpful?
Related resources from Grafana Labs

