Skip to content

Commit

Permalink
fix(reactivity): check type of __ob__ in isRaw and isReactive (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
Djaler committed Jun 17, 2021
1 parent b3ab6f9 commit 97dd671
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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)
})
})

0 comments on commit 97dd671

Please sign in to comment.