Skip to content

Commit

Permalink
test(reactivity): add tests for object with symbols (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax authored Apr 16, 2020
1 parent 09b4202 commit d7ae1d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/reactivity/__tests__/ref.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions test-dts/ref.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit d7ae1d0

Please sign in to comment.