MCPcopy
hub / github.com/vuejs/core / assertHooks

Function assertHooks

packages/runtime-core/__tests__/vnodeHooks.spec.ts:12–39  ·  view source on GitHub ↗
(hooks: VNodeProps, vnode1: VNode, vnode2: VNode)

Source from the content-addressed store, hash-verified

10
11describe('renderer: vnode hooks', () => {
12 function assertHooks(hooks: VNodeProps, vnode1: VNode, vnode2: VNode) {
13 const root = nodeOps.createElement('div')
14 render(vnode1, root)
15 expect(hooks.onVnodeBeforeMount).toHaveBeenCalledWith(vnode1, null)
16 expect(hooks.onVnodeMounted).toHaveBeenCalledWith(vnode1, null)
17 expect(hooks.onVnodeBeforeUpdate).not.toHaveBeenCalled()
18 expect(hooks.onVnodeUpdated).not.toHaveBeenCalled()
19 expect(hooks.onVnodeBeforeUnmount).not.toHaveBeenCalled()
20 expect(hooks.onVnodeUnmounted).not.toHaveBeenCalled()
21
22 // update
23 render(vnode2, root)
24 expect(hooks.onVnodeBeforeMount).toHaveBeenCalledTimes(1)
25 expect(hooks.onVnodeMounted).toHaveBeenCalledTimes(1)
26 expect(hooks.onVnodeBeforeUpdate).toHaveBeenCalledWith(vnode2, vnode1)
27 expect(hooks.onVnodeUpdated).toHaveBeenCalledWith(vnode2, vnode1)
28 expect(hooks.onVnodeBeforeUnmount).not.toHaveBeenCalled()
29 expect(hooks.onVnodeUnmounted).not.toHaveBeenCalled()
30
31 // unmount
32 render(null, root)
33 expect(hooks.onVnodeBeforeMount).toHaveBeenCalledTimes(1)
34 expect(hooks.onVnodeMounted).toHaveBeenCalledTimes(1)
35 expect(hooks.onVnodeBeforeUpdate).toHaveBeenCalledTimes(1)
36 expect(hooks.onVnodeUpdated).toHaveBeenCalledTimes(1)
37 expect(hooks.onVnodeBeforeUnmount).toHaveBeenCalledWith(vnode2, null)
38 expect(hooks.onVnodeUnmounted).toHaveBeenCalledWith(vnode2, null)
39 }
40
41 test('should work on element', () => {
42 const hooks: VNodeProps = {

Callers 1

vnodeHooks.spec.tsFile · 0.85

Calls 2

renderFunction · 0.90
createElementMethod · 0.80

Tested by

no test coverage detected