summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/functions/function-new-target.js
blob: 9eb7659391f1b5ce881c52602d02969886b08859 (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
test("basic functionality", () => {
    function foo() {
        return new.target;
    }
    expect(foo()).toBeUndefined();
    expect(new foo()).toEqual(foo);

    function bar() {
        const baz = () => new.target;
        return baz();
    }
    expect(bar()).toBeUndefined();
    expect(new bar()).toEqual(bar);

    class baz {
        constructor() {
            this.newTarget = new.target;
        }
    }
    expect(new baz().newTarget).toEqual(baz);
});

test("syntax error outside of function", () => {
    expect("new.target").not.toEval();
});