Menu
Scroll for more
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Open source
toBeNaN()
The toBeNaN() method asserts that a value is NaN (Not a Number).
Syntax
JavaScript
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
JavaScript
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
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.