]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(reactivity): add tests for object with symbols (#969)
authorCarlos Rodrigues <carlos@hypermob.co.uk>
Thu, 16 Apr 2020 13:24:46 +0000 (14:24 +0100)
committerGitHub <noreply@github.com>
Thu, 16 Apr 2020 13:24:46 +0000 (09:24 -0400)
packages/reactivity/__tests__/ref.spec.ts
test-dts/ref.test-d.ts

index 27c7a0b260d61126dd427fe094f3b4cfc8e12be2..7885ff7d0c881af59cad7a813d05750d54210efa 100644 (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)
index 5d73a38df17e0b980161e5d2071f9aa6ecf50e6d..7aa6c606637ce5e06948102e23a246272c54cefa 100644 (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()