fix(runtime-core/template-ref): template ref used in the same template should trigger update
fix #1505
This commit is contained in:
@@ -5,7 +5,8 @@ import {
|
||||
render,
|
||||
nextTick,
|
||||
defineComponent,
|
||||
reactive
|
||||
reactive,
|
||||
serializeInner
|
||||
} from '@vue/runtime-test'
|
||||
|
||||
// reference: https://vue-composition-api-rfc.netlify.com/api.html#template-refs
|
||||
@@ -246,4 +247,25 @@ describe('api: template refs', () => {
|
||||
expect(refKey2.value).toBe(root.children[2])
|
||||
expect(refKey3.value).toBe(root.children[3])
|
||||
})
|
||||
|
||||
// #1505
|
||||
test('reactive template ref in the same template', async () => {
|
||||
const Comp = {
|
||||
setup() {
|
||||
const el = ref()
|
||||
return { el }
|
||||
},
|
||||
render(this: any) {
|
||||
return h('div', { id: 'foo', ref: 'el' }, this.el && this.el.props.id)
|
||||
}
|
||||
}
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(Comp), root)
|
||||
// ref not ready on first render, but should queue an update immediately
|
||||
expect(serializeInner(root)).toBe(`<div id="foo"></div>`)
|
||||
await nextTick()
|
||||
// ref should be updated
|
||||
expect(serializeInner(root)).toBe(`<div id="foo">foo</div>`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user