Number.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. test("basic functionality", () => {
  2. expect(Number).toHaveLength(1);
  3. expect(Number.name).toBe("Number");
  4. expect(Number.prototype).not.toHaveProperty("length");
  5. expect(typeof Number()).toBe("number");
  6. expect(typeof new Number()).toBe("object");
  7. expect(Number()).toBe(0);
  8. expect(new Number().valueOf()).toBe(0);
  9. expect(Number("42")).toBe(42);
  10. expect(new Number("42").valueOf()).toBe(42);
  11. expect(Number(null)).toBe(0);
  12. expect(new Number(null).valueOf()).toBe(0);
  13. expect(Number(true)).toBe(1);
  14. expect(new Number(true).valueOf()).toBe(1);
  15. expect(Number("Infinity")).toBe(Infinity);
  16. expect(new Number("Infinity").valueOf()).toBe(Infinity);
  17. expect(Number("+Infinity")).toBe(Infinity);
  18. expect(new Number("+Infinity").valueOf()).toBe(Infinity);
  19. expect(Number("-Infinity")).toBe(-Infinity);
  20. expect(new Number("-Infinity").valueOf()).toBe(-Infinity);
  21. expect(Number(undefined)).toBeNaN();
  22. expect(new Number(undefined).valueOf()).toBeNaN();
  23. expect(Number({})).toBeNaN();
  24. expect(new Number({}).valueOf()).toBeNaN();
  25. expect(Number({ a: 1 })).toBeNaN();
  26. expect(new Number({ a: 1 }).valueOf()).toBeNaN();
  27. expect(Number([1, 2, 3])).toBeNaN();
  28. expect(new Number([1, 2, 3]).valueOf()).toBeNaN();
  29. expect(Number("foo")).toBeNaN();
  30. expect(new Number("foo").valueOf()).toBeNaN();
  31. });