effect,
setText,
render,
- getCurrentInstance,
ref,
unmountComponent,
} from '../src'
-import type { ComponentInternalInstance } from '../src'
import { afterEach, beforeEach, describe, expect } from 'vitest'
-import { defineComponent, nextTick } from '@vue/runtime-core'
+import { defineComponent } from '@vue/runtime-core'
let host: HTMLElement
},
})
const instance = render(Comp as any, {}, '#host')
- await nextTick()
expect(host.innerHTML).toBe('<div>0</div>')
unmountComponent(instance)
expect(host.innerHTML).toBe('')
-/**
- * @vitest-environment jsdom
- */
-
import { template, fragment } from '../src'
describe('api: template', () => {
function handleClick() {
visible.value = !visible.value
}
- const __returned__ = { visible, handleClick }
- Object.defineProperty(__returned__, '__isScriptSetup', {
- enumerable: false,
- value: true,
- })
- return __returned__
- },
- render(_ctx: any) {
const t0 = template('<button>toggle</button><h1>hello world</h1>')
const n0 = t0()
const {
0: [n1],
1: [n2],
- } = children(n0 as ChildNode)
- withDirectives(n2, [[vShow, () => _ctx.visible]])
- on(
- n1 as HTMLElement,
- 'click',
- (...args) => _ctx.handleClick && _ctx.handleClick(...args),
- )
+ } = children(n0)
+ withDirectives(n2, [[vShow, () => visible.value]])
+ on(n1 as HTMLElement, 'click', (...args) => handleClick(...args))
return n0
},
})
import { markRaw, proxyRefs } from '@vue/reactivity'
import { type Data } from '@vue/shared'
-
import {
type Component,
type ComponentInternalInstance,
setCurrentInstance,
unsetCurrentInstance,
} from './component'
-
import { initProps } from './componentProps'
-
import { invokeDirectiveHook } from './directive'
-
import { insert, remove } from './dom'
import { PublicInstanceProxyHandlers } from './componentPublicInstance'
} else {
block = state as Block
}
- if (block instanceof DocumentFragment) block = Array.from(block.childNodes)
+ if (block instanceof DocumentFragment) {
+ block = Array.from(block.childNodes)
+ }
return (instance.block = block)
})!
invokeDirectiveHook(instance, 'beforeMount')
queued = undefined
}
-export const nextTick = (fn: any) => p.then(fn)
+export const nextTick = (fn?: any) => (fn ? p.then(fn) : p)
export function effect(fn: any) {
let run: () => void