Skip to content

Commit

Permalink
fix: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jul 25, 2020
1 parent 619332d commit f6db1f5
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion packages/runtime-core/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import {
Teleport,
Text,
ref,
nextTick
nextTick,
openBlock,
createBlock
} from '@vue/runtime-test'
import { createVNode, Fragment } from '../../src/vnode'
import { PatchFlags } from '@vue/shared'

describe('renderer: teleport', () => {
test('should work', () => {
Expand Down Expand Up @@ -299,4 +302,55 @@ describe('renderer: teleport', () => {
)
expect(serializeInner(target)).toBe('')
})

test('should work with block tree', async () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
const disabled = ref(false)

const App = {
render() {
return (
openBlock(),
createBlock(
Fragment,
null,
[
h(
Teleport,
{ to: target, disabled: disabled.value },
h('div', 'teleported')
),
h('div', 'root')
],
PatchFlags.STABLE_FRAGMENT
)
)
}
}
render(h(App), root)
expect(serializeInner(root)).toMatchInlineSnapshot(
`"<!--teleport start--><!--teleport end--><div>root</div>"`
)
expect(serializeInner(target)).toMatchInlineSnapshot(
`"<div>teleported</div>"`
)

disabled.value = true
await nextTick()
expect(serializeInner(root)).toMatchInlineSnapshot(
`"<!--teleport start--><div>teleported</div><!--teleport end--><div>root</div>"`
)
expect(serializeInner(target)).toBe(``)

// toggle back
disabled.value = false
await nextTick()
expect(serializeInner(root)).toMatchInlineSnapshot(
`"<!--teleport start--><!--teleport end--><div>root</div>"`
)
expect(serializeInner(target)).toMatchInlineSnapshot(
`"<div>teleported</div>"`
)
})
})

0 comments on commit f6db1f5

Please sign in to comment.