Proxy.js 965 B

12345678910111213141516171819202122232425262728293031
  1. test("constructs properly", () => {
  2. expect(() => {
  3. new Proxy({}, {});
  4. }).not.toThrow();
  5. });
  6. test("constructor argument count", () => {
  7. expect(() => {
  8. new Proxy();
  9. }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments");
  10. expect(() => {
  11. new Proxy({});
  12. }).toThrowWithMessage(TypeError, "Proxy constructor requires at least two arguments");
  13. });
  14. test("constructor requires objects", () => {
  15. expect(() => {
  16. new Proxy(1, {});
  17. }).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got 1");
  18. expect(() => {
  19. new Proxy({}, 1);
  20. }).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got 1");
  21. });
  22. test("constructor must be invoked with 'new'", () => {
  23. expect(() => {
  24. Proxy({}, {});
  25. }).toThrowWithMessage(TypeError, "Proxy must be called with the 'new' operator");
  26. });