Proxy.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(
  10. TypeError,
  11. "Expected target argument of Proxy constructor to be object, got undefined"
  12. );
  13. expect(() => {
  14. new Proxy({});
  15. }).toThrowWithMessage(
  16. TypeError,
  17. "Expected handler argument of Proxy constructor to be object, got undefined"
  18. );
  19. });
  20. test("constructor requires objects", () => {
  21. expect(() => {
  22. new Proxy(1, {});
  23. }).toThrowWithMessage(
  24. TypeError,
  25. "Expected target argument of Proxy constructor to be object, got 1"
  26. );
  27. expect(() => {
  28. new Proxy({}, 1);
  29. }).toThrowWithMessage(
  30. TypeError,
  31. "Expected handler argument of Proxy constructor to be object, got 1"
  32. );
  33. });
  34. test("constructor must be invoked with 'new'", () => {
  35. expect(() => {
  36. Proxy({}, {});
  37. }).toThrowWithMessage(TypeError, "Proxy constructor must be called with 'new'");
  38. });