Skip to content
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

fix(reactivity): check type of __ob__ in isRaw and isReactive #732

Merged
merged 1 commit into from Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/reactivity/reactive.ts
Expand Up @@ -15,11 +15,15 @@ import { isRef, UnwrapRef } from './ref'
import { rawSet, accessModifiedSet } from '../utils/sets'

export function isRaw(obj: any): boolean {
return Boolean(obj?.__ob__ && obj.__ob__?.__raw__)
return Boolean(
obj?.__ob__ && typeof obj.__ob__ === 'object' && obj.__ob__?.__raw__
)
}

export function isReactive(obj: any): boolean {
return Boolean(obj?.__ob__ && !obj.__ob__?.__raw__)
return Boolean(
obj?.__ob__ && typeof obj.__ob__ === 'object' && !obj.__ob__?.__raw__
)
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/setup.spec.js
Expand Up @@ -1169,4 +1169,28 @@ describe('setup', () => {

expect(warn).not.toBeCalled()
})

it('should work with mock objects', async () => {
const originalProxy = new Proxy(
{},
{
get() {
return jest.fn()
},
}
)

const opts = {
template: `<div/>`,
setup() {
return {
proxy: originalProxy,
}
},
}
const Constructor = Vue.extend(opts).extend({})

const vm = new Vue(Constructor).$mount()
expect(vm.proxy).toBe(originalProxy)
})
})