Symbol.js 774 B

123456789101112131415161718192021222324252627
  1. test("basic functionality", () => {
  2. const s1 = Symbol("foo");
  3. const s2 = Symbol("foo");
  4. expect(s1).not.toBe(s2);
  5. expect(s1.description).toBe("foo");
  6. expect(s2.description).toBe("foo");
  7. s1.description = "bar";
  8. expect(s1.description).toBe("foo");
  9. expect(typeof s1).toBe("symbol");
  10. });
  11. test("constructing symbol from symbol is an error", () => {
  12. expect(() => {
  13. Symbol(Symbol("foo"));
  14. }).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
  15. });
  16. test("setting new properties on a symbol is an error in strict mode", () => {
  17. "use strict";
  18. var symbol = Symbol("foo");
  19. expect(() => {
  20. symbol.bar = 42;
  21. }).toThrowWithMessage(TypeError, "Cannot set property 'bar' of symbol 'Symbol(foo)'");
  22. });