Skip to content

Commit

Permalink
Add tests for globalThis and unexpectedRefCall
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Mar 22, 2020
1 parent f5ea76f commit d523c3d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/lib/rules/no-obj-calls.js
Expand Up @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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" }]
}
]
});

0 comments on commit d523c3d

Please sign in to comment.