-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmount.test.js
34 lines (25 loc) · 923 Bytes
/
mount.test.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
import { act, render, screen } from '@testing-library/svelte'
import { describe, expect, test, vi } from 'vitest'
import Mounter from './fixtures/Mounter.svelte'
import { IS_HAPPYDOM, IS_SVELTE_5 } from './utils.js'
const onMounted = vi.fn()
const onDestroyed = vi.fn()
const renderSubject = () => render(Mounter, { onMounted, onDestroyed })
describe.skipIf(IS_SVELTE_5 && IS_HAPPYDOM)('mount and destroy', () => {
test('component is mounted', async () => {
renderSubject()
const content = screen.getByRole('button')
expect(content).toBeInTheDocument()
await act()
expect(onMounted).toHaveBeenCalledOnce()
})
test('component is destroyed', async () => {
const { unmount } = renderSubject()
await act()
unmount()
const content = screen.queryByRole('button')
expect(content).not.toBeInTheDocument()
await act()
expect(onDestroyed).toHaveBeenCalledOnce()
})
})