source: frontend/node_modules/eslint-plugin-testing-library/rules/no-wait-for-multiple-assertions.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.6 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RULE_NAME = void 0;
4const create_testing_library_rule_1 = require("../create-testing-library-rule");
5const node_utils_1 = require("../node-utils");
6exports.RULE_NAME = 'no-wait-for-multiple-assertions';
7exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
8 name: exports.RULE_NAME,
9 meta: {
10 type: 'suggestion',
11 docs: {
12 description: 'Disallow the use of multiple `expect` calls inside `waitFor`',
13 recommendedConfig: {
14 dom: 'error',
15 angular: 'error',
16 react: 'error',
17 vue: 'error',
18 marko: 'error',
19 },
20 },
21 messages: {
22 noWaitForMultipleAssertion: 'Avoid using multiple assertions within `waitFor` callback',
23 },
24 schema: [],
25 },
26 defaultOptions: [],
27 create(context, _, helpers) {
28 function getExpectNodes(body) {
29 return body.filter((node) => {
30 if (!(0, node_utils_1.isExpressionStatement)(node)) {
31 return false;
32 }
33 const expressionIdentifier = (0, node_utils_1.getPropertyIdentifierNode)(node);
34 if (!expressionIdentifier) {
35 return false;
36 }
37 return expressionIdentifier.name === 'expect';
38 });
39 }
40 function reportMultipleAssertion(node) {
41 if (!node.parent) {
42 return;
43 }
44 const callExpressionNode = node.parent.parent;
45 const callExpressionIdentifier = (0, node_utils_1.getPropertyIdentifierNode)(callExpressionNode);
46 if (!callExpressionIdentifier) {
47 return;
48 }
49 if (!helpers.isAsyncUtil(callExpressionIdentifier, ['waitFor'])) {
50 return;
51 }
52 const expectNodes = getExpectNodes(node.body);
53 if (expectNodes.length <= 1) {
54 return;
55 }
56 for (let i = 0; i < expectNodes.length; i++) {
57 if (i !== 0) {
58 context.report({
59 node: expectNodes[i],
60 messageId: 'noWaitForMultipleAssertion',
61 });
62 }
63 }
64 }
65 return {
66 'CallExpression > ArrowFunctionExpression > BlockStatement': reportMultipleAssertion,
67 'CallExpression > FunctionExpression > BlockStatement': reportMultipleAssertion,
68 };
69 },
70});
Note: See TracBrowser for help on using the repository browser.