Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): instanceWatch should pass this.proxy to source as the first argument #2753

Merged
merged 6 commits into from
Feb 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
nodeOps,
serializeInner,
TestElement,
h
h,
createApp
} from '@vue/runtime-test'
import {
ITERATE_KEY,
Expand Down Expand Up @@ -857,4 +858,27 @@ describe('api: watch', () => {

expect(instance!.effects![0].active).toBe(false)
})

test('this.$watch should pass `this.proxy` to watch source as the first argument ', () => {
let args: any = null
let instance: any

const source = function() {
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
args = arguments
}

const Comp = defineComponent({
render() {},
created(this: any) {
instance = this
this.$watch(source, function() {})
}
})

const root = nodeOps.createElement('div')
createApp(Comp).mount(root)

expect(args.length > 0).toBe(true)
expect(instance === args[0]).toBe(true)
})
})