Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f494ad

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

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

‎package.json‎

Lines changed: 2 additions & 2 deletions
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",

‎src/__tests__/mount.test.js‎

Lines changed: 22 additions & 18 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /