Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Jan 3, 2025
1 parent 9403228 commit 79ad0d2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/runtime-core/__tests__/rendererTemplateRef.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
render,
serializeInner,
shallowRef,
watch,
} from '@vue/runtime-test'

describe('api: template refs', () => {
Expand Down Expand Up @@ -179,6 +180,51 @@ describe('api: template refs', () => {
expect(el.value).toBe(null)
})

// #12639
it('update and unmount child in the same tick', async () => {
const root = nodeOps.createElement('div')
const el = ref(null)
const toggle = ref(true)
const show = ref(true)

const Comp = defineComponent({
emits: ['change'],
props: ['show'],
setup(props, { emit }) {
watch(
() => props.show,
() => {
emit('change')
},
)
return () => h('div', 'hi')
},
})

const App = {
setup() {
return {
refKey: el,
}
},
render() {
return toggle.value
? h(Comp, {
ref: 'refKey',
show: show.value,
onChange: () => (toggle.value = false),
})
: null
},
}
render(h(App), root)
expect(el.value).not.toBe(null)

show.value = false
await nextTick()
expect(el.value).toBe(null)
})

test('string ref inside slots', async () => {
const root = nodeOps.createElement('div')
const spy = vi.fn()
Expand Down

0 comments on commit 79ad0d2

Please sign in to comment.