Skip to content

Commit 97dd671

Browse files
authored
fix(reactivity): check type of __ob__ in isRaw and isReactive (#732)
1 parent b3ab6f9 commit 97dd671

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/reactivity/reactive.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ import { isRef, UnwrapRef } from './ref'
1515
import { rawSet, accessModifiedSet } from '../utils/sets'
1616

1717
export function isRaw(obj: any): boolean {
18-
return Boolean(obj?.__ob__ && obj.__ob__?.__raw__)
18+
return Boolean(
19+
obj?.__ob__ && typeof obj.__ob__ === 'object' && obj.__ob__?.__raw__
20+
)
1921
}
2022

2123
export function isReactive(obj: any): boolean {
22-
return Boolean(obj?.__ob__ && !obj.__ob__?.__raw__)
24+
return Boolean(
25+
obj?.__ob__ && typeof obj.__ob__ === 'object' && !obj.__ob__?.__raw__
26+
)
2327
}
2428

2529
/**

test/setup.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,4 +1169,28 @@ describe('setup', () => {
11691169

11701170
expect(warn).not.toBeCalled()
11711171
})
1172+
1173+
it('should work with mock objects', async () => {
1174+
const originalProxy = new Proxy(
1175+
{},
1176+
{
1177+
get() {
1178+
return jest.fn()
1179+
},
1180+
}
1181+
)
1182+
1183+
const opts = {
1184+
template: `<div/>`,
1185+
setup() {
1186+
return {
1187+
proxy: originalProxy,
1188+
}
1189+
},
1190+
}
1191+
const Constructor = Vue.extend(opts).extend({})
1192+
1193+
const vm = new Vue(Constructor).$mount()
1194+
expect(vm.proxy).toBe(originalProxy)
1195+
})
11721196
})

0 commit comments

Comments
 (0)