close
logo
Rstest
指南
配置
API
English
简体中文
指南
配置
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
📝 在 GitHub 上编辑此页
上一页includeSource
下一页env

#testNamePattern

  • 类型: string | RegExp
  • 默认值: undefined
  • CLI: -t=<value>, --testNamePattern=<value>

仅运行测试名称中匹配正则表达式或字符串的测试。

如果将 testNamePattern 设置为 bar,则测试名称中不包含 bar 的测试将被跳过。

需要注意的是,测试名称由测试用例名称和包裹它的测试套件名称组成。如果测试套件名称中包含 bar,则该测试套件中的所有测试用例都将被运行。

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

如果你希望排除某些测试,可以使用负向正则表达式。例如,/^(?!.*bar).*$/ 将排除所有名称中包含 bar 的测试。

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

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