feat(reactivity): support default value in toRef()
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user