Skip to content

fix(reactivity): ref as a reactive parameter should return (#6358) #6359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into fix/ref-reactive-param
  • Loading branch information
edison1105 authored Aug 23, 2024
commit 73be6d749e2298768dfa77bf3551f76b9ec8877e
69 changes: 69 additions & 0 deletions packages/reactivity/__tests__/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,73 @@ describe('reactivity/reactive', () => {
expect(spy1).toBeCalledTimes(2)
expect(isReactive(obj)).toBe(true)
})

test('hasOwnProperty edge case: Symbol values', () => {
const key = Symbol()
const obj = reactive({ [key]: 1 }) as { [key]?: 1 }
let dummy
effect(() => {
dummy = obj.hasOwnProperty(key)
})
expect(dummy).toBe(true)

delete obj[key]
expect(dummy).toBe(false)
})

test('hasOwnProperty edge case: non-string values', () => {
const key = {}
const obj = reactive({ '[object Object]': 1 }) as { '[object Object]'?: 1 }
let dummy
effect(() => {
// @ts-expect-error
dummy = obj.hasOwnProperty(key)
})
expect(dummy).toBe(true)

// @ts-expect-error
delete obj[key]
expect(dummy).toBe(false)
})

test('isProxy', () => {
const foo = {}
expect(isProxy(foo)).toBe(false)

const fooRe = reactive(foo)
expect(isProxy(fooRe)).toBe(true)

const fooSRe = shallowReactive(foo)
expect(isProxy(fooSRe)).toBe(true)

const barRl = readonly(foo)
expect(isProxy(barRl)).toBe(true)

const barSRl = shallowReadonly(foo)
expect(isProxy(barSRl)).toBe(true)

const c = computed(() => {})
expect(isProxy(c)).toBe(false)
})

test('The results of the shallow and readonly assignments are the same (Map)', () => {
const map = reactive(new Map())
map.set('foo', shallowReactive({ a: 2 }))
expect(isShallow(map.get('foo'))).toBe(true)

map.set('bar', readonly({ b: 2 }))
expect(isReadonly(map.get('bar'))).toBe(true)
})

test('The results of the shallow and readonly assignments are the same (Set)', () => {
const set = reactive(new Set())
set.add(shallowReactive({ a: 2 }))
set.add(readonly({ b: 2 }))
let count = 0
for (const i of set) {
if (count === 0) expect(isShallow(i)).toBe(true)
else expect(isReadonly(i)).toBe(true)
count++
}
})
})
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.