1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 18:25:07 +00:00
serenity/Libraries/LibJS/Tests/new-expression.js
Matthew Olsson eea6041302 LibJS: Convert some top-level tests to the new system
First test conversions! These look really good :)
2020-07-06 23:40:35 +02:00

49 lines
913 B
JavaScript

test("new-expression parsing", () => {
function Foo() { this.x = 1; }
let foo = new Foo();
expect(foo.x).toBe(1);
foo = new Foo
expect(foo.x).toBe(1);
foo = new
Foo
()
expect(foo.x).toBe(1);
foo = new Foo + 2
expect(foo).toBe("[object Object]2");
});
test("new-expressions with object keys", () => {
let a = {
b: function() {
this.x = 2;
},
};
foo = new a.b();
expect(foo.x).toBe(2);
foo = new a.b;
expect(foo.x).toBe(2);
foo = new
a.b();
expect(foo.x).toBe(2);
});
test("new-expressions with function calls", () => {
function funcGetter() {
return function(a, b) {
this.x = a + b;
};
};
foo = new funcGetter()(1, 5);
expect(foo).toBeUndefined();
foo = new (funcGetter())(1, 5);
expect(foo.x).toBe(6);
});