-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmount-legacy.js
47 lines (38 loc) · 1.06 KB
/
mount-legacy.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
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Legacy rendering core for svelte-testing-library.
*
* Supports Svelte <= 4.
*/
import { addCleanupTask, removeCleanupTask } from './cleanup.js'
/** Allowed options for the component constructor. */
const ALLOWED_OPTIONS = [
'target',
'accessors',
'anchor',
'props',
'hydrate',
'intro',
'context',
]
/** Mount the component into the DOM. */
const mount = (Component, options) => {
const component = new Component(options)
/** Remove the component from the DOM. */
const unmount = () => {
component.$destroy()
removeCleanupTask(unmount)
}
/** Update the component's props. */
const rerender = (nextProps) => {
component.$set(nextProps)
}
// This `$$.on_destroy` listener is included for strict backwards compatibility
// with previous versions of `@testing-library/svelte`.
// It's unnecessary and will be removed in a future major version.
component.$$.on_destroy.push(() => {
removeCleanupTask(unmount)
})
addCleanupTask(unmount)
return { component, unmount, rerender }
}
export { ALLOWED_OPTIONS, mount }