Skip to content

Commit 46c2e22

Browse files
committed
fix: test fails for Svelte5 and happy-dom
1 parent d55fbd7 commit 46c2e22

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/__tests__/mount.test.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, test, vi } from 'vitest'
2+
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
23

34
import { act, render, screen } from '..'
45
import Mounter from './fixtures/Mounter.svelte'
@@ -7,27 +8,30 @@ const onMounted = vi.fn()
78
const onDestroyed = vi.fn()
89
const renderSubject = () => render(Mounter, { onMounted, onDestroyed })
910

10-
describe('mount and destroy', () => {
11-
test('component is mounted', async () => {
12-
renderSubject()
11+
describe.skipIf(SVELTE_VERSION >= '5' && process.env.VITEST_ENV == 'happy-dom')(
12+
'mount and destroy',
13+
() => {
14+
test('component is mounted', async () => {
15+
renderSubject()
1316

14-
const content = screen.getByRole('button')
17+
const content = screen.getByRole('button')
1518

16-
expect(content).toBeInTheDocument()
17-
await act()
18-
expect(onMounted).toHaveBeenCalledOnce()
19-
})
19+
expect(content).toBeInTheDocument()
20+
await act()
21+
expect(onMounted).toHaveBeenCalledOnce()
22+
})
2023

21-
test('component is destroyed', async () => {
22-
const { unmount } = renderSubject()
24+
test('component is destroyed', async () => {
25+
const { unmount } = renderSubject()
2326

24-
await act()
25-
unmount()
27+
await act()
28+
unmount()
2629

27-
const content = screen.queryByRole('button')
30+
const content = screen.queryByRole('button')
2831

29-
expect(content).not.toBeInTheDocument()
30-
await act()
31-
expect(onDestroyed).toHaveBeenCalledOnce()
32-
})
33-
})
32+
expect(content).not.toBeInTheDocument()
33+
await act()
34+
expect(onDestroyed).toHaveBeenCalledOnce()
35+
})
36+
}
37+
)

0 commit comments

Comments
 (0)