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

test(runtime-core): modify test for #2295 #2309

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Changes from all commits
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
18 changes: 17 additions & 1 deletion packages/runtime-core/__tests__/rendererComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,32 @@ describe('renderer: component', () => {
})

// #2170
test('should have access to instance’s “$el” property in watcher when rendereing with watched prop', async () => {
test('instance.$el should be exposed to watch options', async () => {
function returnThis(this: any) {
return this
}
const propWatchSpy = jest.fn(returnThis)
const dataWatchSpy = jest.fn(returnThis)
let instance: any
const Comp = {
props: {
testProp: String
},

data() {
return {
testData: undefined
}
},

watch: {
testProp() {
// @ts-ignore
propWatchSpy(this.$el)
},
testData() {
// @ts-ignore
dataWatchSpy(this.$el)
}
},

Expand All @@ -172,10 +183,15 @@ describe('renderer: component', () => {
render(h(Comp), root)
await nextTick()
expect(propWatchSpy).not.toHaveBeenCalled()
expect(dataWatchSpy).not.toHaveBeenCalled()

render(h(Comp, { testProp: 'prop ' }), root)
await nextTick()
expect(propWatchSpy).toHaveBeenCalledWith(instance.$el)

instance.testData = 1
await nextTick()
expect(dataWatchSpy).toHaveBeenCalledWith(instance.$el)
})

// #2200
Expand Down