Skip to content

Commit 55d98fd

Browse files
committed
Add constants for different queries variants, methods and combinations
1 parent 5ea05bb commit 55d98fd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

lib/utils.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
11
'use strict';
22

3+
const combineQueries = (variants, methods) => {
4+
const combinedQueries = [];
5+
variants.forEach(variant => {
6+
const variantPrefix = variant.replace('By', '');
7+
methods.forEach(method => {
8+
combinedQueries.push(`${variantPrefix}${method}`);
9+
});
10+
});
11+
12+
return combinedQueries;
13+
};
14+
315
const getDocsUrl = ruleName =>
416
`https://github.com/Belco90/eslint-plugin-testing-library/tree/master/docs/rules/${ruleName}.md`;
517

18+
const SYNC_QUERIES_VARIANTS = ['getBy', 'getAllBy', 'queryBy', 'queryAllBy'];
19+
const ASYNC_QUERIES_VARIANTS = ['findBy', 'findAllBy'];
20+
const ALL_QUERIES_VARIANTS = [
21+
...SYNC_QUERIES_VARIANTS,
22+
...ASYNC_QUERIES_VARIANTS,
23+
];
24+
25+
const ALL_QUERIES_METHODS = [
26+
'ByLabelText',
27+
'ByPlaceholderText',
28+
'ByText',
29+
'ByAltText',
30+
'ByTitle',
31+
'ByDisplayValue',
32+
'ByRole',
33+
'ByTestId',
34+
];
35+
36+
const SYNC_QUERIES_COMBINATIONS = combineQueries(
37+
SYNC_QUERIES_VARIANTS,
38+
ALL_QUERIES_METHODS
39+
);
40+
41+
const ASYNC_QUERIES_COMBINATIONS = combineQueries(
42+
ASYNC_QUERIES_VARIANTS,
43+
ALL_QUERIES_METHODS
44+
);
45+
46+
const ALL_QUERIES_COMBINATIONS = [
47+
SYNC_QUERIES_COMBINATIONS,
48+
ASYNC_QUERIES_COMBINATIONS,
49+
];
50+
651
module.exports = {
752
getDocsUrl,
53+
SYNC_QUERIES_VARIANTS,
54+
ASYNC_QUERIES_VARIANTS,
55+
ALL_QUERIES_VARIANTS,
56+
ALL_QUERIES_METHODS,
57+
SYNC_QUERIES_COMBINATIONS,
58+
ASYNC_QUERIES_COMBINATIONS,
59+
ALL_QUERIES_COMBINATIONS,
860
};

0 commit comments

Comments
 (0)