Proxy.js 1009 B

12345678910111213141516171819202122232425262728293031323334353637
  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(
  18. TypeError,
  19. "Expected target argument of Proxy constructor to be object, got 1"
  20. );
  21. expect(() => {
  22. new Proxy({}, 1);
  23. }).toThrowWithMessage(
  24. TypeError,
  25. "Expected handler argument of Proxy constructor to be object, got 1"
  26. );
  27. });
  28. test("constructor must be invoked with 'new'", () => {
  29. expect(() => {
  30. Proxy({}, {});
  31. }).toThrowWithMessage(TypeError, "Proxy must be called with the 'new' operator");
  32. });