fix(reactivity): fix shallow readonly behavior for collections (#3003)

fix #3007
This commit is contained in:
HcySunYang
2021-03-27 03:10:21 +08:00
committed by GitHub
parent 9cb21d088e
commit 68de9f408a
5 changed files with 393 additions and 35 deletions

View File

@@ -7,7 +7,6 @@ import {
markRaw,
effect,
ref,
shallowReadonly,
isProxy,
computed
} from '../src'
@@ -455,32 +454,4 @@ describe('reactivity/readonly', () => {
'Set operation on key "randomProperty" failed: target is readonly.'
).toHaveBeenWarned()
})
describe('shallowReadonly', () => {
test('should not make non-reactive properties reactive', () => {
const props = shallowReadonly({ n: { foo: 1 } })
expect(isReactive(props.n)).toBe(false)
})
test('should make root level properties readonly', () => {
const props = shallowReadonly({ n: 1 })
// @ts-ignore
props.n = 2
expect(props.n).toBe(1)
expect(
`Set operation on key "n" failed: target is readonly.`
).toHaveBeenWarned()
})
// to retain 2.x behavior.
test('should NOT make nested properties readonly', () => {
const props = shallowReadonly({ n: { foo: 1 } })
// @ts-ignore
props.n.foo = 2
expect(props.n.foo).toBe(2)
expect(
`Set operation on key "foo" failed: target is readonly.`
).not.toHaveBeenWarned()
})
})
})