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/tocontain.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/jslib/testing/non-retrying-assertions/tocontain/. 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.
toContain()
The toContain() method asserts that an array contains a specific item or a string contains a substring.
Syntax
expect(actual).toContain(expected);
expect(actual).not.toContain(expected);Parameters
| Parameter | Type | Description |
|---|---|---|
| expected | any | The value to search for |
Returns
| Type | Description |
|---|---|
| void | No return value |
Description
The toContain() method checks if:
- An array contains a specific element (using
includes()) - A string contains a substring (using
includes())
For arrays, it uses strict equality (===) to match elements. For more complex object matching in arrays, use toContainEqual().
Usage
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export default function () {
const numbers = [1, 2, 3, 4, 5];
expect(numbers).toContain(3);
expect(numbers).not.toContain(6);
const fruits = ['apple', 'banana', 'orange'];
expect(fruits).toContain('banana');
expect(fruits).not.toContain('grape');
}Was this page helpful?
Related resources from Grafana Labs

