summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/strict-mode-errors.js
blob: 632895df20fcb232a691b021845b3344641d3be9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"use strict";

test("basic functionality", () => {
    [true, false, "foo", 123].forEach(primitive => {
        expect(() => {
            primitive.foo = "bar";
        }).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${primitive}`);
        expect(() => {
            primitive[Symbol.hasInstance] = 123;
        }).toThrowWithMessage(
            TypeError,
            `Cannot set property 'Symbol(Symbol.hasInstance)' of ${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`);
    });
});