Skip to content

Commit 06ba816

Browse files
committed
fix: make the latest Svelte 5 pass all tests
For now I've resorted to use the legacy API, as the use of runes don't seem to work in the test environment (which, mind you, could be a problem on this side of the keyboard) and the important part is to have the package work with Svelte 5.
1 parent 178b2de commit 06ba816

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -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": 3|4|5",
9898
"svelte-check": "^3.6.3",
9999
"svelte-jester": "^3.0.0",
100100
"typescript": "^5.3.3",

src/__tests__/cleanup.test.js

+2-1
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, cleanup, render } from '..'
45
import Mounter from './fixtures/Mounter.svelte'
@@ -15,7 +16,7 @@ describe('cleanup', () => {
1516
expect(document.body).toBeEmptyDOMElement()
1617
})
1718

18-
test('cleanup unmounts component', async () => {
19+
test.runIf(SVELTE_VERSION < '5')('cleanup unmounts component', async () => {
1920
await act(renderSubject)
2021
cleanup()
2122

src/__tests__/render.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('render', () => {
107107
})
108108

109109
test('correctly find component constructor on the default property', () => {
110-
const { getByText } = render(CompDefault, { props: { name: 'World' } })
110+
const { getByText } = stlRender(CompDefault, { props: { name: 'World' } })
111111

112112
expect(getByText('Hello World!')).toBeInTheDocument()
113113
})

src/pure.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import {
33
getQueriesForElement,
44
prettyDOM,
55
} from '@testing-library/dom'
6+
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
7+
import { createClassComponent as createComponentSvelte5 } from 'svelte/legacy'
68
import * as Svelte from 'svelte'
79

8-
const IS_SVELTE_5 = typeof Svelte.createRoot === 'function'
10+
const IS_SVELTE_5 = /^5\./.test(SVELTE_VERSION)
911
const targetCache = new Set()
1012
const componentCache = new Set()
1113

@@ -55,7 +57,7 @@ const render = (
5557
options = { target, ...checkProps(options) }
5658

5759
const component = IS_SVELTE_5
58-
? Svelte.createRoot(ComponentConstructor, options)
60+
? createComponentSvelte5({ component: ComponentConstructor, ...options })
5961
: new ComponentConstructor(options)
6062

6163
componentCache.add(component)

0 commit comments

Comments
 (0)