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
bail
retry
testTimeout
hookTimeout
maxConcurrency
pool
isolate
testEnvironment
clearMocks
resetMocks
restoreMocks
unstubEnvs
unstubGlobals
coverage
reporters
logHeapUsage
hideSkippedTests
slowTestThreshold
snapshotFormat
chaiConfig
resolveSnapshotPath
printConsoleTrace
onConsoleLog
disableConsoleIntercept

Build Configurations

plugins
source
output
resolve
tools
dev
performance
📝 Edit this page on GitHub
Previous PageincludeSource
Next Pageenv

#testNamePattern

  • Type: string | RegExp
  • Default: undefined
  • CLI: -t=<value>, --testNamePattern=<value>

Run only tests with a name that matches the regex / string.

If you set testNamePattern to bar, tests not containing the word bar in the test name will be skipped.

It should be noted that the test name consists of the test case name and the name of the test suite that wraps it. If a test suite name contains bar, all test cases in that test suite will be run.

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

export default defineConfig({
  testNamePattern: 'bar',
});
// skipped
test('test foo', () => {
  expect(true).toBe(true);
});

// run
test('test bar', () => {
  expect(true).toBe(true);
});

// run all tests in this suite
describe('bar', () => {
  it('should add two numbers correctly', () => {
    expect(1 + 1).toBe(2);
  });
});

If you want to exclude certain tests instead, you can use a negative regex. For example, /^(?!.*bar).*$/ skips every test whose name contains bar.

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

export default defineConfig({
  testNamePattern: /^(?!.*bar).*$/,
});