function-length.js 634 B

1234567891011121314151617181920212223
  1. test("basic functionality", () => {
  2. function foo() {}
  3. expect(foo).toHaveLength(0);
  4. expect((foo.length = 5)).toBe(5);
  5. expect(foo).toHaveLength(0);
  6. function bar(a, b, c) {}
  7. expect(bar).toHaveLength(3);
  8. expect((bar.length = 5)).toBe(5);
  9. expect(bar).toHaveLength(3);
  10. });
  11. test("functions with special parameter lists", () => {
  12. function baz(a, b = 1, c) {}
  13. expect(baz).toHaveLength(1);
  14. expect((baz.length = 5)).toBe(5);
  15. expect(baz).toHaveLength(1);
  16. function qux(a, b, ...c) {}
  17. expect(qux).toHaveLength(2);
  18. expect((qux.length = 2)).toBe(2);
  19. expect(qux).toHaveLength(2);
  20. });