For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt, and this page is available as Markdown at https://rstest.rs/api/runtime-api/test-api/assert.md.
close
  • English
  • assert

    Rstest re-exports Chai's assert API for TDD-style assertions. You can import assert directly from @rstest/core, or access it globally when globals is enabled.

    • Type: typeof import('chai').assert

    Example

    import { assert, test } from '@rstest/core';
    
    test('basic assertions', () => {
      assert.equal(1 + 1, 2);
      assert.strictEqual('rstest', 'rstest');
      assert.deepEqual({ a: 1 }, { a: 1 });
      assert.isTrue(Array.isArray([1, 2, 3]));
      assert.throws(() => {
        throw new Error('boom');
      }, /boom/);
    });

    Common methods

    MethodDescription
    assert(expression, message?)Fails if expression is falsy.
    assert.equal(actual, expected, message?)Asserts non-strict equality (==).
    assert.strictEqual(actual, expected, message?)Asserts strict equality (===).
    assert.deepEqual(actual, expected, message?)Asserts deep structural equality.
    assert.isTrue(value, message?) / assert.isFalse(value, message?)Asserts strict boolean true / false.
    assert.isNull(value, message?) / assert.isUndefined(value, message?)Asserts null / undefined.
    assert.include(haystack, needle, message?)Asserts a string, array, or object contains needle.
    assert.throws(fn, errorLike?, errMsgMatcher?, message?)Asserts fn throws a matching error.

    For the full list of assertion methods and options, see the Chai Assert API.