]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Tests for no-proto rule. | |
3 | * @author Ilya Volodin | |
4 | */ | |
5 | ||
6 | "use strict"; | |
7 | ||
8 | //------------------------------------------------------------------------------ | |
9 | // Requirements | |
10 | //------------------------------------------------------------------------------ | |
11 | ||
12 | const rule = require("../../../lib/rules/no-proto"), | |
13 | { RuleTester } = require("../../../lib/rule-tester"); | |
14 | ||
15 | //------------------------------------------------------------------------------ | |
16 | // Tests | |
17 | //------------------------------------------------------------------------------ | |
18 | ||
19 | const ruleTester = new RuleTester(); | |
20 | ||
21 | ruleTester.run("no-proto", rule, { | |
22 | valid: [ | |
23 | "var a = test[__proto__];", | |
24 | "var __proto__ = null;", | |
25 | { code: "foo[`__proto`] = null;", parserOptions: { ecmaVersion: 6 } }, | |
609c276f TL |
26 | { code: "foo[`__proto__\n`] = null;", parserOptions: { ecmaVersion: 6 } }, |
27 | { code: "class C { #__proto__; foo() { this.#__proto__; } }", parserOptions: { ecmaVersion: 2022 } } | |
eb39fafa DC |
28 | ], |
29 | invalid: [ | |
30 | { code: "var a = test.__proto__;", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, | |
31 | { code: "var a = test['__proto__'];", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, | |
32 | { code: "var a = test[`__proto__`];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, | |
33 | { code: "test[`__proto__`] = function () {};", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] } | |
34 | ] | |
35 | }); |