55 lines
764 B
JavaScript
55 lines
764 B
JavaScript
const a = {
|
|
"3": "three",
|
|
"foo": "bar"
|
|
}
|
|
|
|
const {
|
|
[3]: omit,
|
|
...rest
|
|
} = a;
|
|
|
|
expect(rest).toEqual({"foo": "bar"});
|
|
expect(omit).toBe("three");
|
|
|
|
const [k1, k2, k3, k4, k5] = [null, undefined, true, false, {toString() { return "warrior"; }}];
|
|
const c = {
|
|
[k1]: "1",
|
|
[k2]: "2",
|
|
[k3]: "3",
|
|
[k4]: "4",
|
|
[k5]: "5"
|
|
};
|
|
|
|
const {
|
|
[k1]: v1,
|
|
[k2]: v2,
|
|
[k3]: v3,
|
|
[k4]: v4,
|
|
[k5]: v5,
|
|
...vrest
|
|
} = c;
|
|
|
|
expect(v1).toBe("1");
|
|
expect(v2).toBe("2");
|
|
expect(v3).toBe("3");
|
|
expect(v4).toBe("4");
|
|
expect(v5).toBe("5");
|
|
expect(vrest).toEqual({});
|
|
|
|
// shouldn't convert symbols to strings
|
|
const sx = Symbol();
|
|
const sy = Symbol();
|
|
|
|
const d = {
|
|
[sx]: "sx",
|
|
[sy]: "sy"
|
|
}
|
|
|
|
const {
|
|
[sx]: dx,
|
|
[sy]: dy
|
|
} = d;
|
|
|
|
expect(dx).toBe("sx");
|
|
expect(dy).toBe("sy");
|