import { ref, watchEffect } from '@vue/runtime-dom'
-import { setText, template } from '../src'
+import { renderEffect, setText, template } from '../src'
import { makeRender } from './_utils'
+import type { VaporComponentInstance } from '../src/component'
const define = makeRender()
+// TODO port tests from rendererComponent.spec.ts
+
describe('component', () => {
test('unmountComponent', async () => {
- const { host, app } = define(() => {
+ const { host, app, instance } = define(() => {
const count = ref(0)
const t0 = template('<div></div>')
const n0 = t0()
watchEffect(() => {
setText(n0, count.value)
})
+ renderEffect(() => {})
return n0
}).render()
+
+ const i = instance as VaporComponentInstance
+ expect(i.scope.effects.length).toBe(2)
expect(host.innerHTML).toBe('<div>0</div>')
+
app.unmount()
expect(host.innerHTML).toBe('')
+ expect(i.scope.effects.length).toBe(0)
})
})
-import {
- createComponent,
- getCurrentInstance,
- nextTick,
- ref,
- setInheritAttrs,
- setText,
- template,
- watchEffect,
-} from '../src'
+import { nextTick, ref, watchEffect } from '@vue/runtime-dom'
+import { createComponent, setText, template } from '../src'
import { makeRender } from './_utils'
const define = makeRender<any>()
-describe.todo('attribute fallthrough', () => {
+describe('attribute fallthrough', () => {
it('should allow attrs to fallthrough', async () => {
const t0 = template('<div>')
const { component: Child } = define({
props: ['foo'],
- render() {
- const instance = getCurrentInstance()!
+ setup(props: any) {
const n0 = t0() as Element
- setInheritAttrs()
- watchEffect(() => setText(n0, instance.props.foo))
+ watchEffect(() => setText(n0, props.foo))
return n0
},
})
const id = ref('a')
const { host } = define({
setup() {
- return { foo, id }
- },
- render(_ctx: Record<string, any>) {
return createComponent(
Child,
- [
- {
- foo: () => _ctx.foo,
- id: () => _ctx.id,
- },
- ],
+ {
+ foo: () => foo.value,
+ id: () => id.value,
+ },
null,
true,
)
const { component: Child } = define({
props: ['foo'],
inheritAttrs: false,
- render() {
- const instance = getCurrentInstance()!
+ setup(props: any) {
const n0 = t0() as Element
- setInheritAttrs()
- watchEffect(() => setText(n0, instance.props.foo))
+ watchEffect(() => setText(n0, props.foo))
return n0
},
})
const id = ref('a')
const { host } = define({
setup() {
- return { foo, id }
- },
- render(_ctx: Record<string, any>) {
return createComponent(
Child,
- [
- {
- foo: () => _ctx.foo,
- id: () => _ctx.id,
- },
- ],
+ {
+ foo: () => foo.value,
+ id: () => id.value,
+ },
null,
true,
)
const t0 = template('<div>')
const { component: Grandson } = define({
props: ['custom-attr'],
- render() {
- const instance = getCurrentInstance()!
+ setup(_: any, { attrs }: any) {
const n0 = t0() as Element
- setInheritAttrs()
- watchEffect(() => setText(n0, instance.attrs.foo))
+ watchEffect(() => setText(n0, attrs.foo))
return n0
},
})
const { component: Child } = define({
- render() {
+ setup() {
const n0 = createComponent(
Grandson,
- [
- {
- 'custom-attr': () => 'custom-attr',
- },
- ],
+ {
+ 'custom-attr': () => 'custom-attr',
+ },
null,
true,
)
const id = ref('a')
const { host } = define({
setup() {
- return { foo, id }
- },
- render(_ctx: Record<string, any>) {
return createComponent(
Child,
- [
- {
- foo: () => _ctx.foo,
- id: () => _ctx.id,
- },
- ],
+ {
+ foo: () => foo.value,
+ id: () => id.value,
+ },
null,
true,
)