fix(reactivity): fix shallow/readonly edge cases

This commit is contained in:
Evan You
2022-07-22 11:10:52 +08:00
parent 8dcb6c7bbd
commit a95554d35c
5 changed files with 69 additions and 14 deletions

View File

@@ -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)
})
})