Skip to content

contain

.contain()

When the tested value is a string, it asserts that the given string val is a substring of the target. \n\n

Asserts that a string contains specified substrings.

Examples

Basic Usage

expect("hello world").to.contain("world");
expect("hello world").to.contain("hello");
expect("hello world").to.contain("world");

With Negation

expect("hello world").to.not.contain("foo");

What Failures Look Like

When the assertion fails, you’ll see a clear error message:

// This would fail:
expect("hello world").to.contain("foo");

Modifiers

This assertion supports the following modifiers:

  • .not - Negates the assertion
  • .to - Language chain (no effect)
  • .be - Language chain (no effect)