From 97dd67132a4c083c2fb01298ee9b979b46e03669 Mon Sep 17 00:00:00 2001 From: Kirill Romanov Date: Thu, 17 Jun 2021 22:31:14 +0300 Subject: [PATCH] fix(reactivity): check type of __ob__ in isRaw and isReactive (#732) --- src/reactivity/reactive.ts | 8 ++++++-- test/setup.spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) 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) + }) })