From d7ae1d0244ed77206b47c822509e0893b3870259 Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Thu, 16 Apr 2020 14:24:46 +0100 Subject: [PATCH] test(reactivity): add tests for object with symbols (#969) --- packages/reactivity/__tests__/ref.spec.ts | 15 +++++++++++++++ test-dts/ref.test-d.ts | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/reactivity/__tests__/ref.spec.ts b/packages/reactivity/__tests__/ref.spec.ts index 27c7a0b2..7885ff7d 100644 --- a/packages/reactivity/__tests__/ref.spec.ts +++ b/packages/reactivity/__tests__/ref.spec.ts @@ -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) diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index 5d73a38d..7aa6c606 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -57,3 +57,20 @@ function bailType(arg: HTMLElement | Ref) { } 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 }>(objRef.value[customSymbol]) +} + +withSymbol()