forked from eslint/eslint
/
no-new-native-nonconstructor.js
68 lines (58 loc) · 2.06 KB
/
no-new-native-nonconstructor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @fileoverview Tests for the no-new-native-nonconstructor rule
* @author Sosuke Suzuki
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-new-native-nonconstructor"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({ env: { es2022: true } });
ruleTester.run("no-new-native-nonconstructor", rule, {
valid: [
// Symbol
"var foo = Symbol('foo');",
"function bar(Symbol) { var baz = new Symbol('baz');}",
"function Symbol() {} new Symbol();",
"new foo(Symbol);",
"new foo(bar, Symbol);",
// BigInt
"var foo = BigInt(9007199254740991);",
"function bar(BigInt) { var baz = new BigInt(9007199254740991);}",
"function BigInt() {} new BigInt();",
"new foo(BigInt);",
"new foo(bar, BigInt);"
],
invalid: [
// Symbol
{
code: "var foo = new Symbol('foo');",
errors: [{
message: "`Symbol` cannot be called as a constructor."
}]
},
{
code: "function bar() { return function Symbol() {}; } var baz = new Symbol('baz');",
errors: [{
message: "`Symbol` cannot be called as a constructor."
}]
},
// BigInt
{
code: "var foo = new BigInt(9007199254740991);",
errors: [{
message: "`BigInt` cannot be called as a constructor."
}]
},
{
code: "function bar() { return function BigInt() {}; } var baz = new BigInt(9007199254740991);",
errors: [{
message: "`BigInt` cannot be called as a constructor."
}]
}
]
});