newValue: 3
})
})
+
+ it('runs shared hook fn for each instance', async () => {
+ const fn = jest.fn()
+ const toggle = ref(true)
+ const Comp = {
+ setup() {
+ return () => (toggle.value ? [h(Child), h(Child)] : null)
+ }
+ }
+ const Child = {
+ setup() {
+ onMounted(fn)
+ onBeforeUnmount(fn)
+ return () => h('div')
+ }
+ }
+
+ render(h(Comp), nodeOps.createElement('div'))
+ expect(fn).toHaveBeenCalledTimes(2)
+ toggle.value = false
+ await nextTick()
+ expect(fn).toHaveBeenCalledTimes(4)
+ })
})
(hook: T, target: ComponentInternalInstance | null = currentInstance) =>
// post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
(!isInSSRComponentSetup || lifecycle === LifecycleHooks.SERVER_PREFETCH) &&
- injectHook(lifecycle, hook, target)
+ injectHook(lifecycle, (...args: unknown[]) => hook(...args), target)
export const onBeforeMount = createHook(LifecycleHooks.BEFORE_MOUNT)
export const onMounted = createHook(LifecycleHooks.MOUNTED)