From d523c3dd2c269e2d1a068b53186450b67911e587 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sun, 22 Mar 2020 02:56:37 +0100 Subject: [PATCH] Add tests for globalThis and unexpectedRefCall --- tests/lib/rules/no-obj-calls.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/lib/rules/no-obj-calls.js b/tests/lib/rules/no-obj-calls.js index ca523f08ca7..4c21d9be4c8 100644 --- a/tests/lib/rules/no-obj-calls.js +++ b/tests/lib/rules/no-obj-calls.js @@ -230,6 +230,11 @@ ruleTester.run("no-obj-calls", rule, { env: { es2020: true }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] }, + { + code: "var x = new globalThis.Math();", + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }] + }, { code: "f(globalThis.Math());", env: { es2020: true }, @@ -240,6 +245,11 @@ ruleTester.run("no-obj-calls", rule, { env: { es2020: true }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }] }, + { + code: "new globalThis.Math().foo;", + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }] + }, { code: "var x = globalThis.JSON();", env: { es2020: true }, @@ -263,6 +273,11 @@ ruleTester.run("no-obj-calls", rule, { env: { es2020: true }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, + { + code: "var x = new globalThis.Reflect;", + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] + }, { code: "/*globals Reflect: true*/ Reflect();", env: { es2020: true }, @@ -277,15 +292,29 @@ ruleTester.run("no-obj-calls", rule, { code: "var foo = bar ? baz: JSON; foo();", errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] }, + { + code: "var foo = bar ? baz: JSON; new foo();", + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] + }, { code: "var foo = bar ? baz: globalThis.JSON; foo();", env: { es2020: true }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] }, + { + code: "var foo = bar ? baz: globalThis.JSON; new foo();", + env: { es2020: true }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] + }, { code: "var foo = window.Atomics; foo();", env: { es2020: true, browser: true }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }] + }, + { + code: "var foo = window.Atomics; new foo;", + env: { es2020: true, browser: true }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }] } ] });