pve-eslint/eslint/tests/lib/rules/no-new-native-nonconstructor.js
Dominik Csapak f2a92ac62f import 8.41.0 source
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2023-05-24 18:51:55 +02:00

69 lines
2.1 KiB
JavaScript

/**
* @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."
}]
}
]
});