-
Notifications
You must be signed in to change notification settings - Fork 110
/
teleport.js
41 lines (31 loc) · 1010 Bytes
/
teleport.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {defineComponent} from 'vue'
import '@testing-library/jest-dom'
import {render, fireEvent} from '..'
const ModalButton = defineComponent({
data() {
return {
modalOpen: false,
}
},
template: `
<button @click="modalOpen = true">open</button>
<teleport to="body">
<div v-if="modalOpen" data-testid="teleported-modal">
This is a teleported modal!
<button @click="modalOpen = false">close</button>
</div>
</teleport>
`,
})
test('Teleport', async () => {
const {queryByText, getByText} = render(ModalButton)
expect(queryByText('This is a teleported modal!')).not.toBeInTheDocument()
// Open the modal
await fireEvent.click(getByText('open'))
const modal = getByText('This is a teleported modal!')
expect(modal).toBeInTheDocument()
expect(modal.parentNode.nodeName).toBe('BODY')
// Close the modal
await fireEvent.click(getByText('close'))
expect(queryByText('This is a teleported modal!')).not.toBeInTheDocument()
})