Skip to content

Commit 2b1449b

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

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
"test": "vitest run --coverage",
5757
"test:watch": "vitest",
5858
"test:update": "vitest run --update",
59-
"test:vitest:jsdom": "vitest run --coverage --environment jsdom",
60-
"test:vitest:happy-dom": "vitest run --coverage --environment happy-dom",
59+
"test:vitest:jsdom": "VITEST_ENV=jsdom vitest run --coverage --environment jsdom",
60+
"test:vitest:happy-dom": "VITEST_ENV=happy-dom vitest run --coverage --environment happy-dom",
6161
"types": "svelte-check",
6262
"validate": "npm-run-all test:vitest:* types",
6363
"contributors:add": "all-contributors add",
@@ -94,7 +94,7 @@
9494
"npm-run-all": "^4.1.5",
9595
"prettier": "3.2.4",
9696
"prettier-plugin-svelte": "3.1.2",
97-
"svelte": "^4.2.10",
97+
"svelte": "5.0.0-next.64",
9898
"svelte-check": "^3.6.3",
9999
"svelte-jester": "^3.0.0",
100100
"typescript": "^5.3.3",

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)