ava/prefer-t-regex

February 8, 2026 ยท View on GitHub

๐Ÿ“ Prefer t.regex() over RegExp#test() and String#match().

๐Ÿ’ผ This rule is enabled in the โœ… recommended config.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Translations: Franรงais

The AVA t.regex() assertion can test a string against a regular expression.

This rule will enforce the use of t.regex() instead of manually using RegExp#test(), which will make your code look clearer and produce better failure output.

This rule is fixable. It will replace the use of RegExp#test(), String#match(), or String#search() with t.regex().

Examples

import test from 'ava';

test('main', t => {
	t.true(/\w+/.test('foo')); // โŒ
	t.truthy('foo'.match(/\w+/)); // โŒ
	t.regex('foo', /\w+/); // โœ…
});