summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/strict-mode-errors.js
blob: 8c8d756c4f64f42a698225fdcbf2f4aa0bf23d85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"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, `Cannot set property 'foo' of ${primitive}`);
        expect(() => {
            primitive[Symbol.hasInstance] = 123;
        }).toThrowWithMessage(
            TypeError,
            `Cannot set property 'Symbol(Symbol.hasInstance)' of ${primitive}`
        );
    });
});