diff --git a/src/reactivity/reactive.ts b/src/reactivity/reactive.ts index 38469e2e..827223f6 100644 --- a/src/reactivity/reactive.ts +++ b/src/reactivity/reactive.ts @@ -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__ + ) } /** diff --git a/test/setup.spec.js b/test/setup.spec.js index d63f72c4..527bf89f 100644 --- a/test/setup.spec.js +++ b/test/setup.spec.js @@ -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: `
`, + setup() { + return { + proxy: originalProxy, + } + }, + } + const Constructor = Vue.extend(opts).extend({}) + + const vm = new Vue(Constructor).$mount() + expect(vm.proxy).toBe(originalProxy) + }) })