1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 10:05:07 +00:00
serenity/Libraries/LibJS/Tests/builtins/Proxy/Proxy.js
Linus Groh 1bff65c591 LibJS: Add ErrorType::ConstructorWithoutNew
...and use it in Proxy::call(), rather than having a specific error
type just for that.
2020-12-02 12:52:31 +01:00

37 lines
1,008 B
JavaScript

test("constructs properly", () => {
expect(() => {
new Proxy({}, {});
}).not.toThrow();
});
test("constructor argument count", () => {
expect(() => {
new Proxy();
}).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments");
expect(() => {
new Proxy({});
}).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments");
});
test("constructor requires objects", () => {
expect(() => {
new Proxy(1, {});
}).toThrowWithMessage(
TypeError,
"Expected target argument of Proxy constructor to be object, got 1"
);
expect(() => {
new Proxy({}, 1);
}).toThrowWithMessage(
TypeError,
"Expected handler argument of Proxy constructor to be object, got 1"
);
});
test("constructor must be invoked with 'new'", () => {
expect(() => {
Proxy({}, {});
}).toThrowWithMessage(TypeError, "Proxy constructor must be called with 'new'");
});