String.fromCodePoint.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. test("basic functionality", () => {
  2. expect(String.fromCodePoint).toHaveLength(1);
  3. expect(String.fromCodePoint()).toBe("");
  4. expect(String.fromCodePoint(0)).toBe("\u0000");
  5. expect(String.fromCodePoint(false)).toBe("\u0000");
  6. expect(String.fromCodePoint(null)).toBe("\u0000");
  7. expect(String.fromCodePoint(1)).toBe("\u0001");
  8. expect(String.fromCodePoint(true)).toBe("\u0001");
  9. expect(String.fromCodePoint(0xffff)).toBe("\uffff");
  10. expect(String.fromCodePoint(65)).toBe("A");
  11. expect(String.fromCodePoint(65, 66, 67)).toBe("ABC");
  12. expect(String.fromCodePoint(228, 246, 252)).toBe("äöü");
  13. });
  14. test("errors", () => {
  15. expect(() => {
  16. String.fromCodePoint(NaN);
  17. }).toThrowWithMessage(
  18. RangeError,
  19. "must be an integer no less than 0 and no greater than 0x10FFFF"
  20. );
  21. expect(() => {
  22. String.fromCodePoint(-5);
  23. }).toThrowWithMessage(
  24. RangeError,
  25. "must be an integer no less than 0 and no greater than 0x10FFFF"
  26. );
  27. expect(() => {
  28. String.fromCodePoint(0x123ffff);
  29. }).toThrowWithMessage(
  30. RangeError,
  31. "must be an integer no less than 0 and no greater than 0x10FFFF"
  32. );
  33. });