2020-07-05 17:26:26 -07:00
|
|
|
test("basic functionality", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
const s1 = Symbol("foo");
|
|
|
|
|
const s2 = Symbol("foo");
|
2020-04-29 23:25:21 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(s1).not.toBe(s2);
|
|
|
|
|
expect(s1.description).toBe("foo");
|
|
|
|
|
expect(s2.description).toBe("foo");
|
2020-04-29 23:25:21 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
s1.description = "bar";
|
|
|
|
|
expect(s1.description).toBe("foo");
|
2020-04-29 23:25:21 -07:00
|
|
|
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(typeof s1).toBe("symbol");
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-07-05 09:27:00 -07:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test("constructing symbol from symbol is an error", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(() => {
|
|
|
|
|
Symbol(Symbol("foo"));
|
|
|
|
|
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2023-07-02 20:33:58 +02:00
|
|
|
|
|
|
|
|
test("setting new properties on a symbol is an error in strict mode", () => {
|
|
|
|
|
"use strict";
|
|
|
|
|
var symbol = Symbol("foo");
|
|
|
|
|
expect(() => {
|
|
|
|
|
symbol.bar = 42;
|
|
|
|
|
}).toThrowWithMessage(TypeError, "Cannot set property 'bar' of Symbol(foo)");
|
|
|
|
|
});
|