feat(reactivity): support default value in toRef()

This commit is contained in:
Evan You
2021-12-11 16:41:58 +08:00
parent d0ea900922
commit 2db9c909c2
3 changed files with 41 additions and 3 deletions

View File

@@ -269,6 +269,18 @@ describe('reactivity/ref', () => {
expect(toRef(r, 'x')).toBe(r.x)
})
test('toRef default value', () => {
const a: { x: number | undefined } = { x: undefined }
const x = toRef(a, 'x', 1)
expect(x.value).toBe(1)
a.x = 2
expect(x.value).toBe(2)
a.x = undefined
expect(x.value).toBe(1)
})
test('toRefs', () => {
const a = reactive({
x: 1,