| 1 |
const sym = Symbol("test"); |
| 2 |
const sym2 = Symbol("not enumerable"); |
| 3 |
|
| 4 |
const src = { a: "string" }; |
| 5 |
Object.defineProperty(src, "b", { value: "not enumerable" }) |
| 6 |
Object.defineProperty(src, sym, { enumerable: true, value: "symbol" }); |
| 7 |
Object.defineProperty(src, sym2, { value: "not enumerable" }); |
| 8 |
|
| 9 |
const {...rest} = src; |
| 10 |
|
| 11 |
expect(rest[sym]).toBe("symbol"); |
| 12 |
expect(rest.a).toBe("string"); |
| 13 |
expect(Object.getOwnPropertyNames(rest)).toEqual(["a"]); |
| 14 |
expect(Object.getOwnPropertySymbols(rest)).toEqual([sym]); |
| 15 |
|
| 16 |
const { [sym]: dst, ...noSym } = src; |
| 17 |
|
| 18 |
expect(dst).toBe("symbol"); |
| 19 |
expect(noSym.a).toBe("string"); |
| 20 |
expect(Object.getOwnPropertySymbols(noSym)).toEqual([]); |