summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/throw-basic.js
blob: b393763d92c7562f7190c4c438f7ce1989524146 (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
30
31
32
33
34
test("throw literal", () => {
    try {
        throw 1;
        expect().fail();
    } catch (e) {
        if (e.name === "ExpectationError") throw e;
        expect(e).toBe(1);
    }
});

test("throw array", () => {
    try {
        throw [99];
        expect().fail();
    } catch (e) {
        if (e.name === "ExpectationError") throw e;
        expect(e).toEqual([99]);
    }
});

test("call function that throws", () => {
    function foo() {
        throw "hello";
        expect().fail();
    }

    try {
        foo();
        expect().fail();
    } catch (e) {
        if (e.name === "ExpectationError") throw e;
        expect(e).toBe("hello");
    }
});