From: Evan You Date: Fri, 30 Aug 2019 17:48:27 +0000 (-0400) Subject: test: add test case for regsitering onBeforeUnmount inside onMounted X-Git-Tag: v3.0.0-alpha.0~865 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1d55b368e8ad46352e5b5a1e39aa08e0b6b3a233;p=thirdparty%2Fvuejs%2Fcore.git test: add test case for regsitering onBeforeUnmount inside onMounted --- diff --git a/packages/runtime-core/__tests__/apiLifecycle.spec.ts b/packages/runtime-core/__tests__/apiLifecycle.spec.ts index 8798b5ae90..91b7a11669 100644 --- a/packages/runtime-core/__tests__/apiLifecycle.spec.ts +++ b/packages/runtime-core/__tests__/apiLifecycle.spec.ts @@ -153,6 +153,36 @@ describe('api: lifecycle hooks', () => { expect(fn).toHaveBeenCalledTimes(1) }) + it('onBeforeUnmount in onMounted', async () => { + const toggle = ref(true) + const root = nodeOps.createElement('div') + const fn = jest.fn(() => { + // should be called before inner div is removed + expect(serializeInner(root)).toBe(`
`) + }) + + const Comp = { + setup() { + return () => (toggle.value ? h(Child) : null) + } + } + + const Child = { + setup() { + onMounted(() => { + onBeforeUnmount(fn) + }) + return () => h('div') + } + } + + render(h(Comp), root) + + toggle.value = false + await nextTick() + expect(fn).toHaveBeenCalledTimes(1) + }) + it('lifecycle call order', async () => { const count = ref(0) const root = nodeOps.createElement('div') @@ -313,6 +343,4 @@ describe('api: lifecycle hooks', () => { newValue: 3 }) }) - - test.todo('onErrorCaptured') })