test(reactivity): add tests for object with symbols (#969)

This commit is contained in:
Carlos Rodrigues 2020-04-16 14:24:46 +01:00 committed by GitHub
parent 09b4202a22
commit d7ae1d0244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -139,6 +139,21 @@ describe('reactivity/ref', () => {
expect(tupleRef.value[4].value).toBe(1)
})
it('should keep symbols', () => {
const customSymbol = Symbol()
const obj = {
[Symbol.asyncIterator]: { a: 1 },
[Symbol.unscopables]: { b: '1' },
[customSymbol]: { c: [1, 2, 3] }
}
const objRef = ref(obj)
expect(objRef.value[Symbol.asyncIterator]).toBe(obj[Symbol.asyncIterator])
expect(objRef.value[Symbol.unscopables]).toBe(obj[Symbol.unscopables])
expect(objRef.value[customSymbol]).toStrictEqual(obj[customSymbol])
})
test('unref', () => {
expect(unref(1)).toBe(1)
expect(unref(ref(1))).toBe(1)

View File

@ -57,3 +57,20 @@ function bailType(arg: HTMLElement | Ref<HTMLElement>) {
}
const el = document.createElement('DIV')
bailType(el)
function withSymbol() {
const customSymbol = Symbol()
const obj = {
[Symbol.asyncIterator]: { a: 1 },
[Symbol.unscopables]: { b: '1' },
[customSymbol]: { c: [1, 2, 3] }
}
const objRef = ref(obj)
expectType<{ a: number }>(objRef.value[Symbol.asyncIterator])
expectType<{ b: string }>(objRef.value[Symbol.unscopables])
expectType<{ c: Array<number> }>(objRef.value[customSymbol])
}
withSymbol()