Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 955 Bytes

prefer-t-regex.md

File metadata and controls

39 lines (25 loc) · 955 Bytes

Prefer using t.regex() to test regular expressions

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().

Fail

const test = require('ava');

test('main', t => {
	t.true(/\w+/.test('foo'));
});
const test = require('ava');

test('main', t => {
	t.truthy('foo'.match(/\w+/));
});

Pass

const test = require('ava');

test('main', async t => {
	t.regex('foo', /\w+/);
});