Skip to content

Commit 6df3675

Browse files
authored
test(runtime-core): improve test for #2295 (#2309)
1 parent 02f355e commit 6df3675

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/runtime-core/__tests__/rendererComponent.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,32 @@ describe('renderer: component', () => {
141141
})
142142

143143
// #2170
144-
test('should have access to instance’s “$el” property in watcher when rendereing with watched prop', async () => {
144+
test('instance.$el should be exposed to watch options', async () => {
145145
function returnThis(this: any) {
146146
return this
147147
}
148148
const propWatchSpy = jest.fn(returnThis)
149+
const dataWatchSpy = jest.fn(returnThis)
149150
let instance: any
150151
const Comp = {
151152
props: {
152153
testProp: String
153154
},
154155

156+
data() {
157+
return {
158+
testData: undefined
159+
}
160+
},
161+
155162
watch: {
156163
testProp() {
157164
// @ts-ignore
158165
propWatchSpy(this.$el)
166+
},
167+
testData() {
168+
// @ts-ignore
169+
dataWatchSpy(this.$el)
159170
}
160171
},
161172

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

176188
render(h(Comp, { testProp: 'prop ' }), root)
177189
await nextTick()
178190
expect(propWatchSpy).toHaveBeenCalledWith(instance.$el)
191+
192+
instance.testData = 1
193+
await nextTick()
194+
expect(dataWatchSpy).toHaveBeenCalledWith(instance.$el)
179195
})
180196

181197
// #2200

0 commit comments

Comments
 (0)