Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

toBeDefined()

The toBeDefined() method asserts that a value is defined, meaning it is not undefined.

Syntax

JavaScript
expect(actual).toBeDefined();
expect(actual).not.toBeDefined();

Returns

TypeDescription
voidNo return value

Description

The toBeDefined() method checks if a value is defined (not undefined). It passes for all values except undefined, including null, false, 0, empty strings, and empty objects/arrays.

Usage

JavaScript
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';

export default function () {
  expect(null).toBeDefined();
  expect(false).toBeDefined();
  expect(0).toBeDefined();
  expect('').toBeDefined();
  expect([]).toBeDefined();
  expect({}).toBeDefined();
  expect(NaN).toBeDefined();
}