Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 1.81 KB

File metadata and controls

39 lines (24 loc) · 1.81 KB

testing-library/no-global-regexp-flag-in-query

📝 Disallow the use of the global RegExp flag (/g) in queries.

💼 This rule is enabled in the following configs: badge-angular angular, badge-dom dom, badge-marko marko, badge-react react, badge-svelte svelte, badge-vue vue.

🔧 This rule is automatically fixable by the --fix CLI option.

Ensure that there are no global RegExp flags used when using queries.

Rule Details

A RegExp instance that's using the global flag /g holds state and this might cause false-positives while querying for elements.

Examples of incorrect code for this rule:

screen.getByText(/hello/gi);
await screen.findByRole('button', { otherProp: true, name: /hello/g });

Examples of correct code for this rule:

screen.getByText(/hello/i);
await screen.findByRole('button', { otherProp: true, name: /hello/ });

Further Reading