2020-07-03 22:43:08 -07:00
|
|
|
test("constructs properly", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
new Proxy({}, {});
|
|
|
|
|
}).not.toThrow();
|
2020-07-03 22:43:08 -07:00
|
|
|
});
|
2020-06-03 14:34:52 -07:00
|
|
|
|
2020-07-03 22:43:08 -07:00
|
|
|
test("constructor argument count", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
new Proxy();
|
2021-06-08 21:46:45 +01:00
|
|
|
}).toThrowWithMessage(
|
|
|
|
|
TypeError,
|
|
|
|
|
"Expected target argument of Proxy constructor to be object, got undefined"
|
|
|
|
|
);
|
2020-06-03 14:34:52 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
new Proxy({});
|
2021-06-08 21:46:45 +01:00
|
|
|
}).toThrowWithMessage(
|
|
|
|
|
TypeError,
|
|
|
|
|
"Expected handler argument of Proxy constructor to be object, got undefined"
|
|
|
|
|
);
|
2020-07-03 22:43:08 -07:00
|
|
|
});
|
2020-06-03 14:34:52 -07:00
|
|
|
|
2020-07-03 22:43:08 -07:00
|
|
|
test("constructor requires objects", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
new Proxy(1, {});
|
|
|
|
|
}).toThrowWithMessage(
|
|
|
|
|
TypeError,
|
|
|
|
|
"Expected target argument of Proxy constructor to be object, got 1"
|
|
|
|
|
);
|
2020-07-03 22:43:08 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
new Proxy({}, 1);
|
|
|
|
|
}).toThrowWithMessage(
|
|
|
|
|
TypeError,
|
|
|
|
|
"Expected handler argument of Proxy constructor to be object, got 1"
|
|
|
|
|
);
|
2020-07-03 22:43:08 -07:00
|
|
|
});
|
2020-06-03 14:34:52 -07:00
|
|
|
|
2020-07-03 22:43:08 -07:00
|
|
|
test("constructor must be invoked with 'new'", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
Proxy({}, {});
|
2020-12-02 09:39:20 +00:00
|
|
|
}).toThrowWithMessage(TypeError, "Proxy constructor must be called with 'new'");
|
2020-07-03 22:43:08 -07:00
|
|
|
});
|