fix(reactivity): ensure that shallow and normal proxies are tracked seperately (close #2843) (#2851)
fix #2843
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { shallowReactive, isReactive, reactive } from '../src/reactive'
|
||||
import { isReactive, reactive, shallowReactive } from '../src/reactive'
|
||||
|
||||
import { effect } from '../src/effect'
|
||||
|
||||
describe('shallowReactive', () => {
|
||||
@@ -13,6 +14,16 @@ describe('shallowReactive', () => {
|
||||
expect(isReactive(props.n)).toBe(true)
|
||||
})
|
||||
|
||||
// #2843
|
||||
test('should allow shallow und normal reactive for same target', async () => {
|
||||
const original = { foo: {} }
|
||||
const shallowProxy = shallowReactive(original)
|
||||
const reactiveProxy = reactive(original)
|
||||
expect(shallowProxy).not.toBe(reactiveProxy)
|
||||
expect(isReactive(shallowProxy.foo)).toBe(false)
|
||||
expect(isReactive(reactiveProxy.foo)).toBe(true)
|
||||
})
|
||||
|
||||
describe('collections', () => {
|
||||
test('should be reactive', () => {
|
||||
const shallowSet = shallowReactive(new Set())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isReactive, isReadonly, shallowReadonly } from '../src'
|
||||
import { isReactive, isReadonly, readonly, shallowReadonly } from '../src'
|
||||
|
||||
describe('reactivity/shallowReadonly', () => {
|
||||
test('should not make non-reactive properties reactive', () => {
|
||||
@@ -27,6 +27,16 @@ describe('reactivity/shallowReadonly', () => {
|
||||
).not.toHaveBeenWarned()
|
||||
})
|
||||
|
||||
// #2843
|
||||
test('should differentiate from normal readonly calls', async () => {
|
||||
const original = { foo: {} }
|
||||
const shallowProxy = shallowReadonly(original)
|
||||
const reactiveProxy = readonly(original)
|
||||
expect(shallowProxy).not.toBe(reactiveProxy)
|
||||
expect(isReadonly(shallowProxy.foo)).toBe(false)
|
||||
expect(isReadonly(reactiveProxy.foo)).toBe(true)
|
||||
})
|
||||
|
||||
describe('collection/Map', () => {
|
||||
;[Map, WeakMap].forEach(Collection => {
|
||||
test('should make the map/weak-map readonly', () => {
|
||||
|
||||
Reference in New Issue
Block a user