fix(reactivity): fix shallow/readonly edge cases
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
} from '../src/index'
|
||||
import { computed } from '@vue/runtime-dom'
|
||||
import { shallowRef, unref, customRef, triggerRef } from '../src/ref'
|
||||
import { isShallow } from '../src/reactive'
|
||||
import { isShallow, readonly, shallowReactive } from '../src/reactive'
|
||||
|
||||
describe('reactivity/ref', () => {
|
||||
it('should hold a value', () => {
|
||||
@@ -400,4 +400,22 @@ describe('reactivity/ref', () => {
|
||||
b.value = obj
|
||||
expect(spy2).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
test('ref should preserve value shallow/readonly-ness', () => {
|
||||
const original = {}
|
||||
const r = reactive(original)
|
||||
const s = shallowReactive(original)
|
||||
const rr = readonly(original)
|
||||
const a = ref(original)
|
||||
|
||||
expect(a.value).toBe(r)
|
||||
|
||||
a.value = s
|
||||
expect(a.value).toBe(s)
|
||||
expect(a.value).not.toBe(r)
|
||||
|
||||
a.value = rr
|
||||
expect(a.value).toBe(rr)
|
||||
expect(a.value).not.toBe(r)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user