Skip to content

Commit 22c34f7

Browse files
authored
docs: Add example using portal-vue (#136)
* Install dep * Add basic example
1 parent 3f5b5f5 commit 22c34f7

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"jest-serializer-vue": "^2.0.2",
5454
"kcd-scripts": "^5.4.0",
5555
"lodash.merge": "^4.6.2",
56+
"portal-vue": "^2.1.7",
5657
"vee-validate": "^2.2.15",
5758
"vue": "^2.6.11",
5859
"vue-i18n": "^8.15.5",

src/__tests__/vue-portal.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {render, waitFor} from '@testing-library/vue'
2+
import '@testing-library/jest-dom/extend-expect'
3+
import PortalVue from 'portal-vue'
4+
5+
const PortalComponent = {
6+
template: `
7+
<div>
8+
<Portal to="portalName" data-testid="portal">
9+
<p>Content rendered wherever the portal-target is located.</p>
10+
</Portal>
11+
12+
<PortalTarget name="portalName" data-testid="target" />
13+
</div>`,
14+
}
15+
16+
test('portal', async () => {
17+
const {getByTestId} = render(PortalComponent, {}, vue => {
18+
vue.use(PortalVue)
19+
})
20+
21+
// wait until PortalVue has removed content from the source element
22+
// and moved it to the target one.
23+
await waitFor(() => {
24+
expect(getByTestId('portal')).toBeEmpty()
25+
})
26+
27+
expect(getByTestId('target')).toHaveTextContent(
28+
'Content rendered wherever the portal-target is located.',
29+
)
30+
})

0 commit comments

Comments
 (0)