ladybird/Userland/Libraries/LibJS/Tests/strict-mode-errors.js

27 lines
920 B
JavaScript
Raw Normal View History

"use strict";
test("basic functionality", () => {
[true, false, "foo", 123].forEach(primitive => {
expect(() => {
primitive.foo = "bar";
}).toThrowWithMessage(
TypeError,
`Cannot set property 'foo' of ${typeof primitive} '${primitive}'`
);
expect(() => {
primitive[Symbol.hasInstance] = 123;
}).toThrowWithMessage(
TypeError,
`Cannot set property 'Symbol(Symbol.hasInstance)' of ${typeof primitive} '${primitive}'`
);
});
[null, undefined].forEach(primitive => {
expect(() => {
primitive.foo = "bar";
}).toThrowWithMessage(TypeError, `${primitive} cannot be converted to an object`);
expect(() => {
primitive[Symbol.hasInstance] = 123;
}).toThrowWithMessage(TypeError, `${primitive} cannot be converted to an object`);
});
});