source: frontend/node_modules/eslint-plugin-jest/lib/rules/require-to-throw-message.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _utils = require("./utils");
9
10var _default = (0, _utils.createRule)({
11 name: __filename,
12 meta: {
13 docs: {
14 category: 'Best Practices',
15 description: 'Require a message for `toThrow()`',
16 recommended: false
17 },
18 messages: {
19 addErrorMessage: 'Add an error message to {{ matcherName }}()'
20 },
21 type: 'suggestion',
22 schema: []
23 },
24 defaultOptions: [],
25
26 create(context) {
27 return {
28 CallExpression(node) {
29 var _matcher$arguments;
30
31 if (!(0, _utils.isExpectCall)(node)) {
32 return;
33 }
34
35 const {
36 matcher,
37 modifier
38 } = (0, _utils.parseExpectCall)(node);
39
40 if ((matcher === null || matcher === void 0 ? void 0 : (_matcher$arguments = matcher.arguments) === null || _matcher$arguments === void 0 ? void 0 : _matcher$arguments.length) === 0 && ['toThrow', 'toThrowError'].includes(matcher.name) && (!modifier || !(modifier.name === _utils.ModifierName.not || modifier.negation))) {
41 // Look for `toThrow` calls with no arguments.
42 context.report({
43 messageId: 'addErrorMessage',
44 data: {
45 matcherName: matcher.name
46 },
47 node: matcher.node.property
48 });
49 }
50 }
51
52 };
53 }
54
55});
56
57exports.default = _default;
Note: See TracBrowser for help on using the repository browser.