You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -154,6 +156,8 @@ This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will pri
154
156
function rerender(ui:React.ReactNode):Promise<void>
155
157
```
156
158
159
+
Also records a `react.rerender` trace mark in the [Trace View](/guide/browser/trace-view).
160
+
157
161
It is better if you test the component that's doing the prop updating to ensure that the props are being updated correctly to avoid relying on implementation details in your tests. That said, if you'd prefer to update the props of a rendered component in your test, this function can be used to update props of the rendered component.
Also records a `react.unmount` trace mark in the [Trace View](/guide/browser/trace-view).
179
+
174
180
This will cause the rendered component to be unmounted. This is useful for testing what happens when your component is removed from the page (liketestingthatyoudon't leave event handlers hanging around causing memory leaks).
The`render`function supports either options that you can pass down to [`mount`](https://svelte.dev/docs/svelte/imperative-component-api#mount) or props directly:
48
59
49
60
```ts
50
-
const screen = render(Component, {
61
+
const screen = await render(Component, {
51
62
props: { // [!code --]
52
63
initialCount: 1, // [!code --]
53
64
}, // [!code --]
@@ -68,7 +79,7 @@ For example, if you are unit testing a `tbody` element, it cannot be a child of
68
79
```ts
69
80
const table = document.createElement('table')
70
81
71
-
const screen = render(TableBody, {
82
+
const screen = await render(TableBody, {
72
83
props,
73
84
// ⚠️ appending the element to `body` manually before rendering
74
85
target: document.body.appendChild(table),
@@ -86,7 +97,7 @@ If the `target` is specified, then this defaults to that, otherwise this default
86
97
Inadditiontodocumentedreturnvalue, the`render`functionalsoreturnsallavailable [locators](/api/browser/locators) relative to the [`baseElement`](#baseelement), including [custom ones](/api/browser/locators#custom-locators).
@@ -118,7 +129,7 @@ The [locator](/api/browser/locators) of your `container`. It is useful to use qu
118
129
```ts
119
130
import { render } from 'vitest-browser-svelte'
120
131
121
-
const { locator } = render(NumberDisplay, {
132
+
const { locator } = await render(NumberDisplay, {
122
133
number: 2,
123
134
})
124
135
@@ -139,15 +150,15 @@ This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will pri
139
150
#### rerender
140
151
141
152
```ts
142
-
function rerender(props: Partial<ComponentProps<T>>): void
153
+
function rerender(props: Partial<ComponentProps<T>>): Promise<void>
143
154
```
144
155
145
-
Updatesthecomponent's props and waits for Svelte to apply the changes. Use this to test how your component responds to prop changes.
156
+
Updatesthecomponent's props and waits for Svelte to apply the changes. Use this to test how your component responds to prop changes. Also records a `svelte.rerender` trace mark in the [Trace View](/guide/browser/trace-view).
The`render`function supports all [`mount` options](https://test-utils.vuejs.org/api/#mount) from `@vue/test-utils` (except `attachTo` - use `container` instead). In addition to them, there are also `container` and `baseElement`.
@@ -56,7 +67,7 @@ For example, if you are unit testing a `tbody` element, it cannot be a child of
56
67
```js
57
68
const table = document.createElement('table')
58
69
59
-
const { container } = render(TableBody, {
70
+
const { container } = await render(TableBody, {
60
71
props,
61
72
// ⚠️ appending the element to `body` manually before rendering
62
73
container: document.body.appendChild(table),
@@ -72,7 +83,7 @@ If the `container` is specified, then this defaults to that, otherwise this defa
72
83
Inadditiontodocumentedreturnvalue, the`render`functionalsoreturnsallavailable [locators](/api/browser/locators) relative to the [`baseElement`](#baseelement), including [custom ones](/api/browser/locators#custom-locators).
Itisbetterifyoutestthecomponentthat's doing the prop updating to ensure that the props are being updated correctly to avoid relying on implementation details in your tests. That said, if you'dprefertoupdatethepropsofarenderedcomponentinyourtest, thisfunction can be used to update props of the rendered component.
0 commit comments