Skip to content

Commit feb813d

Browse files
committed
test(runtime-vapor): component emits (does not emit after unmount)
1 parent 0d17ba7 commit feb813d

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

packages/runtime-vapor/__tests__/componentEmits.spec.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
// Note: emits and listener fallthrough is tested in
44
// ./rendererAttrsFallthrough.spec.ts.
55

6-
import { defineComponent, render } from '../src'
6+
import {
7+
defineComponent,
8+
nextTick,
9+
onBeforeUnmount,
10+
render,
11+
unmountComponent,
12+
} from '../src'
713
import { isEmitListener } from '../src/componentEmits'
814

915
let host: HTMLElement
@@ -443,7 +449,32 @@ describe('component: emit', () => {
443449
expect(isEmitListener(options, 'onFooBaz')).toBe(true)
444450
})
445451

446-
test.todo('does not emit after unmount', async () => {})
452+
test('does not emit after unmount', async () => {
453+
const fn = vi.fn()
454+
const Foo = defineComponent({
455+
emits: ['closing'],
456+
setup(_: any, { emit }: any) {
457+
onBeforeUnmount(async () => {
458+
await nextTick()
459+
emit('closing', true)
460+
})
461+
},
462+
render() {},
463+
})
464+
const i = render(
465+
Foo,
466+
{
467+
get onClosing() {
468+
return fn
469+
},
470+
},
471+
'#host',
472+
)
473+
await nextTick()
474+
unmountComponent(i)
475+
await nextTick()
476+
expect(fn).not.toHaveBeenCalled()
477+
})
447478

448479
test.todo('merge string array emits', async () => {})
449480

0 commit comments

Comments
 (0)