fix(reactivity): fix shallow readonly behavior for collections (#3003)
fix #3007
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user