source: frontend/node_modules/eslint-plugin-testing-library/rules/no-wait-for-snapshot.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.5 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RULE_NAME = void 0;
4const utils_1 = require("@typescript-eslint/utils");
5const create_testing_library_rule_1 = require("../create-testing-library-rule");
6const node_utils_1 = require("../node-utils");
7exports.RULE_NAME = 'no-wait-for-snapshot';
8const SNAPSHOT_REGEXP = /^(toMatchSnapshot|toMatchInlineSnapshot)$/;
9exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
10 name: exports.RULE_NAME,
11 meta: {
12 type: 'problem',
13 docs: {
14 description: 'Ensures no snapshot is generated inside of a `waitFor` call',
15 recommendedConfig: {
16 dom: 'error',
17 angular: 'error',
18 react: 'error',
19 vue: 'error',
20 marko: 'error',
21 },
22 },
23 messages: {
24 noWaitForSnapshot: "A snapshot can't be generated inside of a `{{ name }}` call",
25 },
26 schema: [],
27 },
28 defaultOptions: [],
29 create(context, _, helpers) {
30 function getClosestAsyncUtil(node) {
31 let n = node;
32 do {
33 const callExpression = (0, node_utils_1.findClosestCallExpressionNode)(n);
34 if (!callExpression) {
35 return null;
36 }
37 if (utils_1.ASTUtils.isIdentifier(callExpression.callee) &&
38 helpers.isAsyncUtil(callExpression.callee)) {
39 return callExpression.callee;
40 }
41 if ((0, node_utils_1.isMemberExpression)(callExpression.callee) &&
42 utils_1.ASTUtils.isIdentifier(callExpression.callee.property) &&
43 helpers.isAsyncUtil(callExpression.callee.property)) {
44 return callExpression.callee.property;
45 }
46 if (callExpression.parent) {
47 n = (0, node_utils_1.findClosestCallExpressionNode)(callExpression.parent);
48 }
49 } while (n !== null);
50 return null;
51 }
52 return {
53 [`Identifier[name=${String(SNAPSHOT_REGEXP)}]`](node) {
54 const closestAsyncUtil = getClosestAsyncUtil(node);
55 if (closestAsyncUtil === null) {
56 return;
57 }
58 context.report({
59 node,
60 messageId: 'noWaitForSnapshot',
61 data: { name: closestAsyncUtil.name },
62 });
63 },
64 };
65 },
66});
Note: See TracBrowser for help on using the repository browser.