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/tobeinstanceof.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/jslib/testing/non-retrying-assertions/tobeinstanceof/. 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.
toBeInstanceOf()
The toBeInstanceOf() method asserts that a value is an instance of a specific class or constructor function.
Syntax
expect(actual).toBeInstanceOf(expected);
expect(actual).not.toBeInstanceOf(expected);Parameters
| Parameter | Type | Description |
|---|---|---|
| expected | Function | The constructor function or class to check against |
Returns
| Type | Description |
|---|---|
| void | No return value |
Description
The toBeInstanceOf() method uses the instanceof operator to check if the actual value is an instance of the expected constructor or class. It checks the prototype chain to determine if the constructor function appears anywhere in the object’s prototype chain.
Usage
import http from 'k6/http';
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
class User {
constructor(name) {
this.name = name;
}
}
export default function () {
const response = http.get('https://quickpizza.grafana.com/');
// Check response object types
expect(response).toBeInstanceOf(Object);
expect(response.headers).toBeInstanceOf(Object);
// Check built-in types
expect([1, 2, 3]).toBeInstanceOf(Array);
expect(new Date()).toBeInstanceOf(Date);
// Check custom classes
const user = new User('John');
expect(user).toBeInstanceOf(User);
expect(user).not.toBeInstanceOf(Array);
}Was this page helpful?
Related resources from Grafana Labs

