close
logo
Rstest
Guide
Config
API
English
简体中文
Guide
Config
API
English
简体中文
logo
Rstest
Overview

Test Configurations

root
name
include
exclude
setupFiles
projects
update
globals
passWithNoTests
includeSource
testNamePattern
env
retry
testTimeout
hookTimeout
maxConcurrency
pool
isolate
testEnvironment
clearMocks
resetMocks
restoreMocks
unstubEnvs
unstubGlobals
coverage
reporters
hideSkippedTests
slowTestThreshold
snapshotFormat
resolveSnapshotPath
printConsoleTrace
onConsoleLog
disableConsoleIntercept

Build Configurations

plugins
source
output
resolve
tools
dev
performance
📝 Edit this page on GitHub
Previous Pageupdate
Next PagepassWithNoTests

#globals

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

Provide global Rstest APIs for test files, such as expect, test, describe, etc.

By default, Rstest does not provide global APIs. If you prefer to use the APIs globally like Jest, you can add globals: true in the config or pass the --globals option to CLI.

CLI
rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  globals: true,
});

#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);
  });
});

#TypeScript support

To enable TypeScript to properly recognize the global APIs, add the @rstest/core/globals type declaration in your tsconfig.json:

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

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

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