Array.of.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. test("length is 0", () => {
  2. expect(Array.of).toHaveLength(0);
  3. });
  4. describe("normal behavior", () => {
  5. test("single numeric argument", () => {
  6. var a = Array.of(5);
  7. expect(a instanceof Array).toBeTrue();
  8. expect(a).toHaveLength(1);
  9. expect(a[0]).toBe(5);
  10. });
  11. test("single non-numeric argument", () => {
  12. var a = Array.of("5");
  13. expect(a instanceof Array).toBeTrue();
  14. expect(a).toHaveLength(1);
  15. expect(a[0]).toBe("5");
  16. });
  17. test("single infinite numeric argument", () => {
  18. var a = Array.of(Infinity);
  19. expect(a instanceof Array).toBeTrue();
  20. expect(a).toHaveLength(1);
  21. expect(a[0]).toBe(Infinity);
  22. });
  23. test("multiple numeric arguments", () => {
  24. var a = Array.of(1, 2, 3);
  25. expect(a instanceof Array).toBeTrue();
  26. expect(a).toHaveLength(3);
  27. expect(a[0]).toBe(1);
  28. expect(a[1]).toBe(2);
  29. expect(a[2]).toBe(3);
  30. });
  31. test("single array argument", () => {
  32. var a = Array.of([1, 2, 3]);
  33. expect(a instanceof Array).toBeTrue();
  34. expect(a).toHaveLength(1);
  35. expect(a[0][0]).toBe(1);
  36. expect(a[0][1]).toBe(2);
  37. expect(a[0][2]).toBe(3);
  38. });
  39. test("getter property is included in returned array", () => {
  40. var t = [1, 2, 3];
  41. Object.defineProperty(t, 3, {
  42. get() {
  43. return 4;
  44. },
  45. });
  46. var a = Array.of(...t);
  47. expect(a).toHaveLength(4);
  48. expect(a[0]).toBe(1);
  49. expect(a[1]).toBe(2);
  50. expect(a[2]).toBe(3);
  51. expect(a[3]).toBe(4);
  52. });
  53. });