Skip to content

Commit 2d3822a

Browse files
committed
document matchers
1 parent 9058db8 commit 2d3822a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,47 @@ test('assertions in `onRender`', async () => {
241241
> passed into `onRender` of React's `Profiler` component, as well as `snapshot`,
242242
> `replaceSnapshot` and `mergeSnapshot`
243243
244+
### `expect(...)[.not].toRerender()` and `expect(...)[.not].toRenderExactlyTimes(n)`
245+
246+
This library adds to matchers to `expect` that can be used like
247+
248+
```tsx
249+
test('basic functionality', async () => {
250+
const {takeRender} = renderToRenderStream(<RerenderingComponent />)
251+
252+
await expect(takeRender).toRerender()
253+
await takeRender()
254+
255+
// trigger a rerender somehow
256+
await expect(takeRender).toRerender()
257+
await takeRender()
258+
259+
// ensure at the end of a test that no more renders will happen
260+
await expect(takeRender).not.toRerender()
261+
await expect(takeRender).toRenderExactlyTimes(2)
262+
})
263+
```
264+
265+
These matchers can be used on multiple different objects:
266+
267+
```ts
268+
await expect(takeRender).toRerender()
269+
await expect(renderStream).toRerender()
270+
await expect(takeSnapshot).toRerender()
271+
await expect(snapshotStream).toRerender()
272+
```
273+
274+
> [!NOTE]
275+
>
276+
> By default, `.toRerender` and `toRenderExactlyTimes` will wait 100ms for
277+
> renders or to ensure no more renders happens.
278+
>
279+
> You can modify that with the `timeout` option:
280+
>
281+
> ```js
282+
> await expect(takeRender).not.toRerender({timeout: 300})
283+
> ```
284+
244285
## A note on `act`.
245286
246287
You might want to avoid using this library with `act`, as `act`

0 commit comments

Comments
 (0)