mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibJS: Indent tests with 4 spaces instead of 2
This commit is contained in:
parent
15de2eda2b
commit
1ef573eb30
261 changed files with 8536 additions and 8497 deletions
|
@ -1,150 +1,150 @@
|
|||
test("no arguments", () => {
|
||||
let getNumber = () => {
|
||||
return 42;
|
||||
};
|
||||
expect(getNumber()).toBe(42);
|
||||
let getNumber = () => {
|
||||
return 42;
|
||||
};
|
||||
expect(getNumber()).toBe(42);
|
||||
|
||||
getNumber = () => 42;
|
||||
expect(getNumber()).toBe(42);
|
||||
getNumber = () => 42;
|
||||
expect(getNumber()).toBe(42);
|
||||
|
||||
getNumber = () => {
|
||||
return 99;
|
||||
};
|
||||
expect(getNumber()).toBe(99);
|
||||
getNumber = () => 99;
|
||||
expect(getNumber()).toBe(99);
|
||||
getNumber = () => {
|
||||
return 99;
|
||||
};
|
||||
expect(getNumber()).toBe(99);
|
||||
getNumber = () => 99;
|
||||
expect(getNumber()).toBe(99);
|
||||
});
|
||||
|
||||
test("arguments", () => {
|
||||
let add = (a, b) => a + b;
|
||||
expect(add(2, 3)).toBe(5);
|
||||
let add = (a, b) => a + b;
|
||||
expect(add(2, 3)).toBe(5);
|
||||
|
||||
const addBlock = (a, b) => {
|
||||
let res = a + b;
|
||||
return res;
|
||||
};
|
||||
expect(addBlock(5, 4)).toBe(9);
|
||||
const addBlock = (a, b) => {
|
||||
let res = a + b;
|
||||
return res;
|
||||
};
|
||||
expect(addBlock(5, 4)).toBe(9);
|
||||
});
|
||||
|
||||
test("inside an array", () => {
|
||||
let chompy = [x => x, 2];
|
||||
expect(chompy).toHaveLength(2);
|
||||
expect(chompy[0](1)).toBe(1);
|
||||
let chompy = [x => x, 2];
|
||||
expect(chompy).toHaveLength(2);
|
||||
expect(chompy[0](1)).toBe(1);
|
||||
});
|
||||
|
||||
test("return object literal", () => {
|
||||
const makeObject = (a, b) => ({ a, b });
|
||||
const obj = makeObject(33, 44);
|
||||
expect(typeof obj).toBe("object");
|
||||
expect(obj.a).toBe(33);
|
||||
expect(obj.b).toBe(44);
|
||||
const makeObject = (a, b) => ({ a, b });
|
||||
const obj = makeObject(33, 44);
|
||||
expect(typeof obj).toBe("object");
|
||||
expect(obj.a).toBe(33);
|
||||
expect(obj.b).toBe(44);
|
||||
});
|
||||
|
||||
test("return undefined", () => {
|
||||
let returnUndefined = () => {};
|
||||
expect(returnUndefined()).toBeUndefined();
|
||||
let returnUndefined = () => {};
|
||||
expect(returnUndefined()).toBeUndefined();
|
||||
});
|
||||
|
||||
test("return array literal", () => {
|
||||
const makeArray = (a, b) => [a, b];
|
||||
const array = makeArray("3", { foo: 4 });
|
||||
expect(array[0]).toBe("3");
|
||||
expect(array[1].foo).toBe(4);
|
||||
const makeArray = (a, b) => [a, b];
|
||||
const array = makeArray("3", { foo: 4 });
|
||||
expect(array[0]).toBe("3");
|
||||
expect(array[1].foo).toBe(4);
|
||||
});
|
||||
|
||||
test("return numeric expression", () => {
|
||||
let square = x => x * x;
|
||||
expect(square(3)).toBe(9);
|
||||
let square = x => x * x;
|
||||
expect(square(3)).toBe(9);
|
||||
|
||||
let squareBlock = x => {
|
||||
return x * x;
|
||||
};
|
||||
expect(squareBlock(4)).toBe(16);
|
||||
let squareBlock = x => {
|
||||
return x * x;
|
||||
};
|
||||
expect(squareBlock(4)).toBe(16);
|
||||
});
|
||||
|
||||
test("return called arrow function expression", () => {
|
||||
const message = (who => "Hello " + who)("friends!");
|
||||
expect(message).toBe("Hello friends!");
|
||||
const message = (who => "Hello " + who)("friends!");
|
||||
expect(message).toBe("Hello friends!");
|
||||
|
||||
const sum = ((x, y, z) => x + y + z)(1, 2, 3);
|
||||
expect(sum).toBe(6);
|
||||
const sum = ((x, y, z) => x + y + z)(1, 2, 3);
|
||||
expect(sum).toBe(6);
|
||||
|
||||
const product = ((x, y, z) => {
|
||||
let res = x * y * z;
|
||||
return res;
|
||||
})(5, 4, 2);
|
||||
expect(product).toBe(40);
|
||||
const product = ((x, y, z) => {
|
||||
let res = x * y * z;
|
||||
return res;
|
||||
})(5, 4, 2);
|
||||
expect(product).toBe(40);
|
||||
|
||||
const half = (x => {
|
||||
return x / 2;
|
||||
})(10);
|
||||
expect(half).toBe(5);
|
||||
const half = (x => {
|
||||
return x / 2;
|
||||
})(10);
|
||||
expect(half).toBe(5);
|
||||
});
|
||||
|
||||
test("currying", () => {
|
||||
let add = a => b => a + b;
|
||||
expect(typeof add(1)).toBe("function");
|
||||
expect(typeof add(1, 2)).toBe("function");
|
||||
expect(add(1)(2)).toBe(3);
|
||||
let add = a => b => a + b;
|
||||
expect(typeof add(1)).toBe("function");
|
||||
expect(typeof add(1, 2)).toBe("function");
|
||||
expect(add(1)(2)).toBe(3);
|
||||
});
|
||||
|
||||
test("with comma operator", () => {
|
||||
let foo, bar;
|
||||
(foo = bar), baz => {};
|
||||
expect(foo).toBe(undefined);
|
||||
expect(bar).toBe(undefined);
|
||||
let foo, bar;
|
||||
(foo = bar), baz => {};
|
||||
expect(foo).toBe(undefined);
|
||||
expect(bar).toBe(undefined);
|
||||
});
|
||||
|
||||
test("arrow functions in objects", () => {
|
||||
function FooBar() {
|
||||
this.x = {
|
||||
y: () => this,
|
||||
z: function () {
|
||||
return (() => this)();
|
||||
},
|
||||
};
|
||||
}
|
||||
function FooBar() {
|
||||
this.x = {
|
||||
y: () => this,
|
||||
z: function () {
|
||||
return (() => this)();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const foobar = new FooBar();
|
||||
expect(foobar.x.y()).toBe(foobar);
|
||||
expect(foobar.x.z()).toBe(foobar.x);
|
||||
const foobar = new FooBar();
|
||||
expect(foobar.x.y()).toBe(foobar);
|
||||
expect(foobar.x.z()).toBe(foobar.x);
|
||||
});
|
||||
|
||||
test("strict mode propogation", () => {
|
||||
(() => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
|
||||
(() => {
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
})();
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
|
||||
(() => {
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
(() => {
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
})();
|
||||
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
})();
|
||||
(() => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
|
||||
(() => {
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
})();
|
||||
});
|
||||
|
||||
test("no prototype", () => {
|
||||
let foo = () => {};
|
||||
expect(foo).not.toHaveProperty("prototype");
|
||||
let foo = () => {};
|
||||
expect(foo).not.toHaveProperty("prototype");
|
||||
});
|
||||
|
||||
test("cannot be constructed", () => {
|
||||
let foo = () => {};
|
||||
expect(() => {
|
||||
new foo();
|
||||
}).toThrowWithMessage(TypeError, "foo is not a constructor");
|
||||
let foo = () => {};
|
||||
expect(() => {
|
||||
new foo();
|
||||
}).toThrowWithMessage(TypeError, "foo is not a constructor");
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
test("basic functionality", () => {
|
||||
function Foo() {
|
||||
this.x = 123;
|
||||
}
|
||||
function Foo() {
|
||||
this.x = 123;
|
||||
}
|
||||
|
||||
expect(Foo.prototype.constructor).toBe(Foo);
|
||||
expect(Foo.prototype.constructor).toBe(Foo);
|
||||
|
||||
const foo = new Foo();
|
||||
expect(foo.constructor).toBe(Foo);
|
||||
expect(foo.x).toBe(123);
|
||||
const foo = new Foo();
|
||||
expect(foo.constructor).toBe(Foo);
|
||||
expect(foo.x).toBe(123);
|
||||
});
|
||||
|
|
|
@ -1,44 +1,47 @@
|
|||
test("calling non-function", () => {
|
||||
expect(() => {
|
||||
const a = true;
|
||||
a();
|
||||
}).toThrowWithMessage(TypeError, "true is not a function (evaluated from 'a')");
|
||||
expect(() => {
|
||||
const a = true;
|
||||
a();
|
||||
}).toThrowWithMessage(TypeError, "true is not a function (evaluated from 'a')");
|
||||
});
|
||||
|
||||
test("calling number", () => {
|
||||
expect(() => {
|
||||
const a = 100 + 20 + 3;
|
||||
a();
|
||||
}).toThrowWithMessage(TypeError, "123 is not a function (evaluated from 'a')");
|
||||
expect(() => {
|
||||
const a = 100 + 20 + 3;
|
||||
a();
|
||||
}).toThrowWithMessage(TypeError, "123 is not a function (evaluated from 'a')");
|
||||
});
|
||||
|
||||
test("calling undefined object key", () => {
|
||||
expect(() => {
|
||||
const o = {};
|
||||
o.a();
|
||||
}).toThrowWithMessage(TypeError, "undefined is not a function (evaluated from 'o.a')");
|
||||
expect(() => {
|
||||
const o = {};
|
||||
o.a();
|
||||
}).toThrowWithMessage(TypeError, "undefined is not a function (evaluated from 'o.a')");
|
||||
});
|
||||
|
||||
test("calling object", () => {
|
||||
expect(() => {
|
||||
Math();
|
||||
}).toThrowWithMessage(TypeError, "[object MathObject] is not a function (evaluated from 'Math')");
|
||||
expect(() => {
|
||||
Math();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"[object MathObject] is not a function (evaluated from 'Math')"
|
||||
);
|
||||
});
|
||||
|
||||
test("constructing object", () => {
|
||||
expect(() => {
|
||||
new Math();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"[object MathObject] is not a constructor (evaluated from 'Math')"
|
||||
);
|
||||
expect(() => {
|
||||
new Math();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"[object MathObject] is not a constructor (evaluated from 'Math')"
|
||||
);
|
||||
});
|
||||
|
||||
test("constructing native function", () => {
|
||||
expect(() => {
|
||||
new isNaN();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"[object NativeFunction] is not a constructor (evaluated from 'isNaN')"
|
||||
);
|
||||
expect(() => {
|
||||
new isNaN();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"[object NativeFunction] is not a constructor (evaluated from 'isNaN')"
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,143 +1,143 @@
|
|||
test("single default parameter", () => {
|
||||
function func(a = 6) {
|
||||
return typeof a;
|
||||
}
|
||||
function func(a = 6) {
|
||||
return typeof a;
|
||||
}
|
||||
|
||||
const arrowFunc = (a = 6) => typeof a;
|
||||
const arrowFunc = (a = 6) => typeof a;
|
||||
|
||||
expect(func()).toBe("number");
|
||||
expect(func(5)).toBe("number");
|
||||
expect(func(undefined)).toBe("number");
|
||||
expect(func(false)).toBe("boolean");
|
||||
expect(func(null)).toBe("object");
|
||||
expect(func({})).toBe("object");
|
||||
expect(func()).toBe("number");
|
||||
expect(func(5)).toBe("number");
|
||||
expect(func(undefined)).toBe("number");
|
||||
expect(func(false)).toBe("boolean");
|
||||
expect(func(null)).toBe("object");
|
||||
expect(func({})).toBe("object");
|
||||
|
||||
expect(arrowFunc()).toBe("number");
|
||||
expect(arrowFunc(5)).toBe("number");
|
||||
expect(arrowFunc(undefined)).toBe("number");
|
||||
expect(arrowFunc(false)).toBe("boolean");
|
||||
expect(arrowFunc(null)).toBe("object");
|
||||
expect(arrowFunc({})).toBe("object");
|
||||
expect(arrowFunc()).toBe("number");
|
||||
expect(arrowFunc(5)).toBe("number");
|
||||
expect(arrowFunc(undefined)).toBe("number");
|
||||
expect(arrowFunc(false)).toBe("boolean");
|
||||
expect(arrowFunc(null)).toBe("object");
|
||||
expect(arrowFunc({})).toBe("object");
|
||||
});
|
||||
|
||||
test("two parameters, second one is default", () => {
|
||||
function func(a, b = 1) {
|
||||
return a + b;
|
||||
}
|
||||
function func(a, b = 1) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc = (a, b = 1) => a + b;
|
||||
const arrowFunc = (a, b = 1) => a + b;
|
||||
|
||||
expect(func(4, 5)).toBe(9);
|
||||
expect(func(4)).toBe(5);
|
||||
expect(func(4, undefined)).toBe(5);
|
||||
expect(func()).toBeNaN();
|
||||
expect(func(4, 5)).toBe(9);
|
||||
expect(func(4)).toBe(5);
|
||||
expect(func(4, undefined)).toBe(5);
|
||||
expect(func()).toBeNaN();
|
||||
|
||||
expect(arrowFunc(4, 5)).toBe(9);
|
||||
expect(arrowFunc(4)).toBe(5);
|
||||
expect(arrowFunc(4, undefined)).toBe(5);
|
||||
expect(arrowFunc()).toBeNaN();
|
||||
expect(arrowFunc(4, 5)).toBe(9);
|
||||
expect(arrowFunc(4)).toBe(5);
|
||||
expect(arrowFunc(4, undefined)).toBe(5);
|
||||
expect(arrowFunc()).toBeNaN();
|
||||
});
|
||||
|
||||
test("two parameters, first one is default", () => {
|
||||
function func(a = 5, b) {
|
||||
return a + b;
|
||||
}
|
||||
function func(a = 5, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc = (a = 5, b) => a + b;
|
||||
const arrowFunc = (a = 5, b) => a + b;
|
||||
|
||||
expect(func(4, 5)).toBe(9);
|
||||
expect(func(undefined, 4)).toBe(9);
|
||||
expect(func()).toBeNaN();
|
||||
expect(func(4, 5)).toBe(9);
|
||||
expect(func(undefined, 4)).toBe(9);
|
||||
expect(func()).toBeNaN();
|
||||
|
||||
expect(arrowFunc(4, 5)).toBe(9);
|
||||
expect(arrowFunc(undefined, 4)).toBe(9);
|
||||
expect(arrowFunc()).toBeNaN();
|
||||
expect(arrowFunc(4, 5)).toBe(9);
|
||||
expect(arrowFunc(undefined, 4)).toBe(9);
|
||||
expect(arrowFunc()).toBeNaN();
|
||||
});
|
||||
|
||||
test("default parameter references a previous parameter", () => {
|
||||
function func(a, b = a) {
|
||||
return a + b;
|
||||
}
|
||||
function func(a, b = a) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
const arrowFunc = (a, b = a) => a + b;
|
||||
const arrowFunc = (a, b = a) => a + b;
|
||||
|
||||
expect(func(4, 5)).toBe(9);
|
||||
expect(func(4)).toBe(8);
|
||||
expect(func("hf")).toBe("hfhf");
|
||||
expect(func(true)).toBe(2);
|
||||
expect(func()).toBeNaN();
|
||||
expect(func(4, 5)).toBe(9);
|
||||
expect(func(4)).toBe(8);
|
||||
expect(func("hf")).toBe("hfhf");
|
||||
expect(func(true)).toBe(2);
|
||||
expect(func()).toBeNaN();
|
||||
|
||||
expect(arrowFunc(4, 5)).toBe(9);
|
||||
expect(arrowFunc(4)).toBe(8);
|
||||
expect(arrowFunc("hf")).toBe("hfhf");
|
||||
expect(arrowFunc(true)).toBe(2);
|
||||
expect(arrowFunc()).toBeNaN();
|
||||
expect(arrowFunc(4, 5)).toBe(9);
|
||||
expect(arrowFunc(4)).toBe(8);
|
||||
expect(arrowFunc("hf")).toBe("hfhf");
|
||||
expect(arrowFunc(true)).toBe(2);
|
||||
expect(arrowFunc()).toBeNaN();
|
||||
});
|
||||
|
||||
test("parameter with a function default value", () => {
|
||||
function func(
|
||||
a = function () {
|
||||
return 5;
|
||||
function func(
|
||||
a = function () {
|
||||
return 5;
|
||||
}
|
||||
) {
|
||||
return a();
|
||||
}
|
||||
) {
|
||||
return a();
|
||||
}
|
||||
|
||||
const arrowFunc = (
|
||||
a = function () {
|
||||
return 5;
|
||||
}
|
||||
) => a();
|
||||
const arrowFunc = (
|
||||
a = function () {
|
||||
return 5;
|
||||
}
|
||||
) => a();
|
||||
|
||||
expect(func()).toBe(5);
|
||||
expect(
|
||||
func(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(func(() => 10)).toBe(10);
|
||||
expect(func()).toBe(5);
|
||||
expect(
|
||||
func(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(func(() => 10)).toBe(10);
|
||||
|
||||
expect(arrowFunc()).toBe(5);
|
||||
expect(
|
||||
arrowFunc(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(arrowFunc(() => 10)).toBe(10);
|
||||
expect(arrowFunc()).toBe(5);
|
||||
expect(
|
||||
arrowFunc(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(arrowFunc(() => 10)).toBe(10);
|
||||
});
|
||||
|
||||
test("parameter with an arrow function default vlaue", () => {
|
||||
function func(a = () => 5) {
|
||||
return a();
|
||||
}
|
||||
function func(a = () => 5) {
|
||||
return a();
|
||||
}
|
||||
|
||||
const arrowFunc = (a = () => 5) => a();
|
||||
const arrowFunc = (a = () => 5) => a();
|
||||
|
||||
expect(func()).toBe(5);
|
||||
expect(
|
||||
func(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(func(() => 10)).toBe(10);
|
||||
expect(arrowFunc()).toBe(5);
|
||||
expect(
|
||||
arrowFunc(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(arrowFunc(() => 10)).toBe(10);
|
||||
expect(func()).toBe(5);
|
||||
expect(
|
||||
func(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(func(() => 10)).toBe(10);
|
||||
expect(arrowFunc()).toBe(5);
|
||||
expect(
|
||||
arrowFunc(function () {
|
||||
return 10;
|
||||
})
|
||||
).toBe(10);
|
||||
expect(arrowFunc(() => 10)).toBe(10);
|
||||
});
|
||||
|
||||
test("parameter with an object default value", () => {
|
||||
function func(a = { foo: "bar" }) {
|
||||
return a.foo;
|
||||
}
|
||||
function func(a = { foo: "bar" }) {
|
||||
return a.foo;
|
||||
}
|
||||
|
||||
const arrowFunc = (a = { foo: "bar" }) => a.foo;
|
||||
const arrowFunc = (a = { foo: "bar" }) => a.foo;
|
||||
|
||||
expect(func()).toBe("bar");
|
||||
expect(func({ foo: "baz" })).toBe("baz");
|
||||
expect(arrowFunc()).toBe("bar");
|
||||
expect(arrowFunc({ foo: "baz" })).toBe("baz");
|
||||
expect(func()).toBe("bar");
|
||||
expect(func({ foo: "baz" })).toBe("baz");
|
||||
expect(arrowFunc()).toBe("bar");
|
||||
expect(arrowFunc({ foo: "baz" })).toBe("baz");
|
||||
});
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
test("basic functionality", () => {
|
||||
let callHoisted = hoisted();
|
||||
function hoisted() {
|
||||
return "foo";
|
||||
}
|
||||
expect(hoisted()).toBe("foo");
|
||||
expect(callHoisted).toBe("foo");
|
||||
let callHoisted = hoisted();
|
||||
function hoisted() {
|
||||
return "foo";
|
||||
}
|
||||
expect(hoisted()).toBe("foo");
|
||||
expect(callHoisted).toBe("foo");
|
||||
});
|
||||
|
||||
// First two calls produce a ReferenceError, but the declarations should be hoisted
|
||||
test.skip("functions are hoisted across non-lexical scopes", () => {
|
||||
expect(scopedHoisted).toBeUndefined();
|
||||
expect(callScopedHoisted).toBeUndefined();
|
||||
{
|
||||
var callScopedHoisted = scopedHoisted();
|
||||
function scopedHoisted() {
|
||||
return "foo";
|
||||
expect(scopedHoisted).toBeUndefined();
|
||||
expect(callScopedHoisted).toBeUndefined();
|
||||
{
|
||||
var callScopedHoisted = scopedHoisted();
|
||||
function scopedHoisted() {
|
||||
return "foo";
|
||||
}
|
||||
expect(scopedHoisted()).toBe("foo");
|
||||
expect(callScopedHoisted).toBe("foo");
|
||||
}
|
||||
expect(scopedHoisted()).toBe("foo");
|
||||
expect(callScopedHoisted).toBe("foo");
|
||||
}
|
||||
expect(scopedHoisted()).toBe("foo");
|
||||
expect(callScopedHoisted).toBe("foo");
|
||||
});
|
||||
|
||||
test("functions are not hoisted across lexical scopes", () => {
|
||||
const test = () => {
|
||||
var iife = (function () {
|
||||
return declaredLater();
|
||||
})();
|
||||
function declaredLater() {
|
||||
return "yay";
|
||||
}
|
||||
return iife;
|
||||
};
|
||||
const test = () => {
|
||||
var iife = (function () {
|
||||
return declaredLater();
|
||||
})();
|
||||
function declaredLater() {
|
||||
return "yay";
|
||||
}
|
||||
return iife;
|
||||
};
|
||||
|
||||
expect(() => declaredLater).toThrow(ReferenceError);
|
||||
expect(test()).toBe("yay");
|
||||
expect(() => declaredLater).toThrow(ReferenceError);
|
||||
expect(test()).toBe("yay");
|
||||
});
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
test("basic functionality", () => {
|
||||
function foo() {}
|
||||
expect(foo).toHaveLength(0);
|
||||
expect((foo.length = 5)).toBe(5);
|
||||
expect(foo).toHaveLength(0);
|
||||
function foo() {}
|
||||
expect(foo).toHaveLength(0);
|
||||
expect((foo.length = 5)).toBe(5);
|
||||
expect(foo).toHaveLength(0);
|
||||
|
||||
function bar(a, b, c) {}
|
||||
expect(bar).toHaveLength(3);
|
||||
expect((bar.length = 5)).toBe(5);
|
||||
expect(bar).toHaveLength(3);
|
||||
function bar(a, b, c) {}
|
||||
expect(bar).toHaveLength(3);
|
||||
expect((bar.length = 5)).toBe(5);
|
||||
expect(bar).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("functions with special parameter lists", () => {
|
||||
function baz(a, b = 1, c) {}
|
||||
expect(baz).toHaveLength(1);
|
||||
expect((baz.length = 5)).toBe(5);
|
||||
expect(baz).toHaveLength(1);
|
||||
function baz(a, b = 1, c) {}
|
||||
expect(baz).toHaveLength(1);
|
||||
expect((baz.length = 5)).toBe(5);
|
||||
expect(baz).toHaveLength(1);
|
||||
|
||||
function qux(a, b, ...c) {}
|
||||
expect(qux).toHaveLength(2);
|
||||
expect((qux.length = 2)).toBe(2);
|
||||
expect(qux).toHaveLength(2);
|
||||
function qux(a, b, ...c) {}
|
||||
expect(qux).toHaveLength(2);
|
||||
expect((qux.length = 2)).toBe(2);
|
||||
expect(qux).toHaveLength(2);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
test("basic functionality", () => {
|
||||
function foo(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
function foo(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
expect(foo()).toBeNaN();
|
||||
expect(foo(1)).toBeNaN();
|
||||
expect(foo(2, 3)).toBe(5);
|
||||
expect(foo(2, 3, 4)).toBe(5);
|
||||
expect(foo()).toBeNaN();
|
||||
expect(foo(1)).toBeNaN();
|
||||
expect(foo(2, 3)).toBe(5);
|
||||
expect(foo(2, 3, 4)).toBe(5);
|
||||
});
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
test("basic functionality", () => {
|
||||
expect(function () {}.name).toBe("");
|
||||
expect(function () {}.name).toBe("");
|
||||
|
||||
function bar() {}
|
||||
expect(bar.name).toBe("bar");
|
||||
expect((bar.name = "baz")).toBe("baz");
|
||||
expect(bar.name).toBe("bar");
|
||||
function bar() {}
|
||||
expect(bar.name).toBe("bar");
|
||||
expect((bar.name = "baz")).toBe("baz");
|
||||
expect(bar.name).toBe("bar");
|
||||
});
|
||||
|
||||
test("function assigned to variable", () => {
|
||||
let foo = function () {};
|
||||
expect(foo.name).toBe("foo");
|
||||
expect((foo.name = "bar")).toBe("bar");
|
||||
expect(foo.name).toBe("foo");
|
||||
let foo = function () {};
|
||||
expect(foo.name).toBe("foo");
|
||||
expect((foo.name = "bar")).toBe("bar");
|
||||
expect(foo.name).toBe("foo");
|
||||
|
||||
let a, b;
|
||||
a = b = function () {};
|
||||
expect(a.name).toBe("b");
|
||||
expect(b.name).toBe("b");
|
||||
let a, b;
|
||||
a = b = function () {};
|
||||
expect(a.name).toBe("b");
|
||||
expect(b.name).toBe("b");
|
||||
});
|
||||
|
||||
test("functions in array assigned to variable", () => {
|
||||
const arr = [function () {}, function () {}, function () {}];
|
||||
expect(arr[0].name).toBe("arr");
|
||||
expect(arr[1].name).toBe("arr");
|
||||
expect(arr[2].name).toBe("arr");
|
||||
const arr = [function () {}, function () {}, function () {}];
|
||||
expect(arr[0].name).toBe("arr");
|
||||
expect(arr[1].name).toBe("arr");
|
||||
expect(arr[2].name).toBe("arr");
|
||||
});
|
||||
|
||||
test("functions in objects", () => {
|
||||
let f;
|
||||
let o = { a: function () {} };
|
||||
let f;
|
||||
let o = { a: function () {} };
|
||||
|
||||
expect(o.a.name).toBe("a");
|
||||
f = o.a;
|
||||
expect(f.name).toBe("a");
|
||||
expect(o.a.name).toBe("a");
|
||||
expect(o.a.name).toBe("a");
|
||||
f = o.a;
|
||||
expect(f.name).toBe("a");
|
||||
expect(o.a.name).toBe("a");
|
||||
|
||||
o = { ...o, b: f };
|
||||
expect(o.a.name).toBe("a");
|
||||
expect(o.b.name).toBe("a");
|
||||
o = { ...o, b: f };
|
||||
expect(o.a.name).toBe("a");
|
||||
expect(o.b.name).toBe("a");
|
||||
|
||||
o.c = function () {};
|
||||
expect(o.c.name).toBe("c");
|
||||
o.c = function () {};
|
||||
expect(o.c.name).toBe("c");
|
||||
});
|
||||
|
||||
test("names of native functions", () => {
|
||||
expect(console.debug.name).toBe("debug");
|
||||
expect((console.debug.name = "warn")).toBe("warn");
|
||||
expect(console.debug.name).toBe("debug");
|
||||
expect(console.debug.name).toBe("debug");
|
||||
expect((console.debug.name = "warn")).toBe("warn");
|
||||
expect(console.debug.name).toBe("debug");
|
||||
});
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
test("rest parameter with no arguments", () => {
|
||||
function foo(...a) {
|
||||
expect(a).toBeInstanceOf(Array);
|
||||
expect(a).toHaveLength(0);
|
||||
}
|
||||
foo();
|
||||
function foo(...a) {
|
||||
expect(a).toBeInstanceOf(Array);
|
||||
expect(a).toHaveLength(0);
|
||||
}
|
||||
foo();
|
||||
});
|
||||
|
||||
test("rest parameter with arguments", () => {
|
||||
function foo(...a) {
|
||||
expect(a).toEqual(["foo", 123, undefined, { foo: "bar" }]);
|
||||
}
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
function foo(...a) {
|
||||
expect(a).toEqual(["foo", 123, undefined, { foo: "bar" }]);
|
||||
}
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
});
|
||||
|
||||
test("rest parameter after normal parameters with no arguments", () => {
|
||||
function foo(a, b, ...c) {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([]);
|
||||
}
|
||||
foo("foo", 123);
|
||||
function foo(a, b, ...c) {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([]);
|
||||
}
|
||||
foo("foo", 123);
|
||||
});
|
||||
|
||||
test("rest parameter after normal parameters with arguments", () => {
|
||||
function foo(a, b, ...c) {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([undefined, { foo: "bar" }]);
|
||||
}
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
function foo(a, b, ...c) {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([undefined, { foo: "bar" }]);
|
||||
}
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
});
|
||||
|
||||
test("basic arrow function rest parameters", () => {
|
||||
let foo = (...a) => {
|
||||
expect(a).toBeInstanceOf(Array);
|
||||
expect(a).toHaveLength(0);
|
||||
};
|
||||
foo();
|
||||
let foo = (...a) => {
|
||||
expect(a).toBeInstanceOf(Array);
|
||||
expect(a).toHaveLength(0);
|
||||
};
|
||||
foo();
|
||||
|
||||
foo = (a, b, ...c) => {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([undefined, { foo: "bar" }]);
|
||||
};
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
foo = (a, b, ...c) => {
|
||||
expect(a).toBe("foo");
|
||||
expect(b).toBe(123);
|
||||
expect(c).toEqual([undefined, { foo: "bar" }]);
|
||||
};
|
||||
foo("foo", 123, undefined, { foo: "bar" });
|
||||
});
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
test("basic functionality", () => {
|
||||
const sum = (a, b, c) => a + b + c;
|
||||
const a = [1, 2, 3];
|
||||
const sum = (a, b, c) => a + b + c;
|
||||
const a = [1, 2, 3];
|
||||
|
||||
expect(sum(...a)).toBe(6);
|
||||
expect(sum(1, ...a)).toBe(4);
|
||||
expect(sum(...a, 10)).toBe(6);
|
||||
expect(sum(...a)).toBe(6);
|
||||
expect(sum(1, ...a)).toBe(4);
|
||||
expect(sum(...a, 10)).toBe(6);
|
||||
|
||||
const foo = (a, b, c) => c;
|
||||
const foo = (a, b, c) => c;
|
||||
|
||||
const o = { bar: [1, 2, 3] };
|
||||
expect(foo(...o.bar)).toBe(3);
|
||||
expect(foo(..."abc")).toBe("c");
|
||||
const o = { bar: [1, 2, 3] };
|
||||
expect(foo(...o.bar)).toBe(3);
|
||||
expect(foo(..."abc")).toBe("c");
|
||||
});
|
||||
|
||||
test("spreading non iterable", () => {
|
||||
expect(() => {
|
||||
[...1];
|
||||
}).toThrowWithMessage(TypeError, "1 is not iterable");
|
||||
expect(() => {
|
||||
[...1];
|
||||
}).toThrowWithMessage(TypeError, "1 is not iterable");
|
||||
});
|
||||
|
|
|
@ -2,52 +2,52 @@
|
|||
// respects the .prettierignore file!
|
||||
|
||||
test("non strict-mode by default", () => {
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
});
|
||||
|
||||
test("use strict with double quotes", () => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
});
|
||||
|
||||
test("use strict with single quotes", () => {
|
||||
'use strict';
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
'use strict';
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
});
|
||||
|
||||
test("use strict with backticks does not yield strict mode", () => {
|
||||
`use strict`;
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
`use strict`;
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
});
|
||||
|
||||
test("use strict with single quotes after statement does not yield strict mode code", () => {
|
||||
;'use strict';
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
;'use strict';
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
});
|
||||
|
||||
test("use strict with double quotes after statement does not yield strict mode code", () => {
|
||||
;"use strict";
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
;"use strict";
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
});
|
||||
|
||||
test("strict mode propogates down the scope chain", () => {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
(function() {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
(function() {
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
});
|
||||
|
||||
test("strict mode does not propogate up the scope chain", () => {
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
(function() {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
(function() {
|
||||
"use strict";
|
||||
expect(isStrictMode()).toBeTrue();
|
||||
})();
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
});
|
||||
|
||||
test('only the string "use strict" yields strict mode code', () => {
|
||||
"use stric";
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
"use stric";
|
||||
expect(isStrictMode()).toBeFalse();
|
||||
});
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
test("basic functionality", () => {
|
||||
expect(typeof this).toBe("object");
|
||||
expect(this).toBe(globalThis);
|
||||
expect(typeof this).toBe("object");
|
||||
expect(this).toBe(globalThis);
|
||||
});
|
||||
|
||||
test("this inside instantiated functions is not globalThis", () => {
|
||||
let functionThis;
|
||||
function Foo() {
|
||||
this.x = 5;
|
||||
functionThis = this;
|
||||
}
|
||||
let functionThis;
|
||||
function Foo() {
|
||||
this.x = 5;
|
||||
functionThis = this;
|
||||
}
|
||||
|
||||
new Foo();
|
||||
expect(typeof functionThis).toBe("object");
|
||||
expect(functionThis.x).toBe(5);
|
||||
new Foo();
|
||||
expect(typeof functionThis).toBe("object");
|
||||
expect(functionThis.x).toBe(5);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue