Skip to content

Commit d7ae1d0

Browse files
authored
test(reactivity): add tests for object with symbols (#969)
1 parent 09b4202 commit d7ae1d0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

packages/reactivity/__tests__/ref.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ describe('reactivity/ref', () => {
139139
expect(tupleRef.value[4].value).toBe(1)
140140
})
141141

142+
it('should keep symbols', () => {
143+
const customSymbol = Symbol()
144+
const obj = {
145+
[Symbol.asyncIterator]: { a: 1 },
146+
[Symbol.unscopables]: { b: '1' },
147+
[customSymbol]: { c: [1, 2, 3] }
148+
}
149+
150+
const objRef = ref(obj)
151+
152+
expect(objRef.value[Symbol.asyncIterator]).toBe(obj[Symbol.asyncIterator])
153+
expect(objRef.value[Symbol.unscopables]).toBe(obj[Symbol.unscopables])
154+
expect(objRef.value[customSymbol]).toStrictEqual(obj[customSymbol])
155+
})
156+
142157
test('unref', () => {
143158
expect(unref(1)).toBe(1)
144159
expect(unref(ref(1))).toBe(1)

test-dts/ref.test-d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ function bailType(arg: HTMLElement | Ref<HTMLElement>) {
5757
}
5858
const el = document.createElement('DIV')
5959
bailType(el)
60+
61+
function withSymbol() {
62+
const customSymbol = Symbol()
63+
const obj = {
64+
[Symbol.asyncIterator]: { a: 1 },
65+
[Symbol.unscopables]: { b: '1' },
66+
[customSymbol]: { c: [1, 2, 3] }
67+
}
68+
69+
const objRef = ref(obj)
70+
71+
expectType<{ a: number }>(objRef.value[Symbol.asyncIterator])
72+
expectType<{ b: string }>(objRef.value[Symbol.unscopables])
73+
expectType<{ c: Array<number> }>(objRef.value[customSymbol])
74+
}
75+
76+
withSymbol()

0 commit comments

Comments
 (0)