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/config/test/globals.md.
close
  • English
  • globals

    • Type: boolean
    • Default: false
    • CLI: --globals

    Inject Rstest APIs (such as expect, test, and describe) into the global scope of test files instead of requiring imports from @rstest/core.

    By default, Rstest does not register global APIs. Set globals: true in config or pass --globals on the CLI to enable them (similar to Jest).

    CLI
    rstest.config.ts
    npx rstest --globals

    Usage

    When you enable globals, you can use the global APIs directly without import { ... } from '@rstest/core'.

    index.test.ts
    - import { describe, expect, it } from '@rstest/core';
    
    describe('Index', () => {
      it('should add two numbers correctly', () => {
        expect(1 + 1).toBe(2);
      });
    });

    Available global APIs

    When globals is enabled, Rstest injects the following globals:

    • test
    • describe
    • it
    • expect
    • assert
    • beforeAll
    • afterAll
    • beforeEach
    • afterEach
    • onTestFinished
    • onTestFailed
    • rs
    • rstest

    rs and rstest are aliases with the same runtime utilities.

    TypeScript support

    To enable TypeScript to properly recognize the global APIs, we recommend adding @rstest/core/globals to compilerOptions.types in the tsconfig.json for your test files:

    tsconfig.json
    {
      "compilerOptions": {
        "types": ["@rstest/core/globals"]
      }
    }

    If your tsconfig.json already configures compilerOptions.types, append this type to the existing list.

    Alternatively, create a src/rstestEnv.d.ts file to reference the type definitions:

    rstestEnv.d.ts
    /// <reference types="@rstest/core/globals" />