nodeOps,
serializeInner,
TestElement,
- h
+ h,
+ createApp
} from '@vue/runtime-test'
import {
ITERATE_KEY,
expect(instance!.effects![0].active).toBe(false)
})
+
+ test('this.$watch should pass `this.proxy` to watch source as the first argument ', () => {
+ let instance: any
+ const source = jest.fn()
+
+ const Comp = defineComponent({
+ render() {},
+ created(this: any) {
+ instance = this
+ this.$watch(source, function() {})
+ }
+ })
+
+ const root = nodeOps.createElement('div')
+ createApp(Comp).mount(root)
+
+ expect(instance).toBeDefined()
+ expect(source).toHaveBeenCalledWith(instance)
+ })
})
} else if (isReactive(s)) {
return traverse(s)
} else if (isFunction(s)) {
- return callWithErrorHandling(s, instance, ErrorCodes.WATCH_GETTER)
+ return callWithErrorHandling(s, instance, ErrorCodes.WATCH_GETTER, [
+ instance && (instance.proxy as any)
+ ])
} else {
__DEV__ && warnInvalidSource(s)
}
if (cb) {
// getter with cb
getter = () =>
- callWithErrorHandling(source, instance, ErrorCodes.WATCH_GETTER)
+ callWithErrorHandling(source, instance, ErrorCodes.WATCH_GETTER, [
+ instance && (instance.proxy as any)
+ ])
} else {
// no cb -> simple effect
getter = () => {