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/tobetruthy.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/jslib/testing/non-retrying-assertions/tobetruthy/. 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.
toBeTruthy()
The toBeTruthy() method asserts that a value is truthy in JavaScript. A value is truthy if it converts to true when evaluated in a boolean context.
Syntax
expect(actual).toBeTruthy();
expect(actual).not.toBeTruthy();Returns
| Type | Description |
|---|---|
| void | No return value |
Description
The toBeTruthy() method checks if a value is truthy. In JavaScript, all values are truthy except for the following falsy values:
false0-00n(BigInt)""(empty string)nullundefinedNaN
Usage
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export default function () {
expect(true).toBeTruthy();
expect(1).toBeTruthy();
expect(-1).toBeTruthy();
expect('hello').toBeTruthy();
expect(' ').toBeTruthy(); // Non-empty string
expect(42).toBeTruthy();
expect(3.14).toBeTruthy();
expect(Infinity).toBeTruthy();
expect(-Infinity).toBeTruthy();
}Was this page helpful?
Related resources from Grafana Labs

