1- import type { MatcherFunction } from 'expect'
2- import { WaitForRenderTimeoutError } from '@testing-library/react-render-stream'
3- import type {
4- Assertable ,
5- NextRenderOptions ,
6- RenderStream ,
1+ import { MatcherContext , type MatcherFunction } from 'expect'
2+ import {
3+ WaitForRenderTimeoutError ,
4+ type Assertable ,
5+ type NextRenderOptions ,
6+ type RenderStream ,
77} from '@testing-library/react-render-stream'
88// explicitly imported the symbol from the internal file
99// this will bundle the `Symbol.for` call twice, but we keep it private
@@ -24,7 +24,7 @@ export interface RenderStreamMatchers<R = void, T = {}> {
2424}
2525
2626export const toRerender : MatcherFunction < [ options ?: NextRenderOptions ] > =
27- async function ( actual , options ) {
27+ async function toRerender ( this : MatcherContext , actual , options ) {
2828 const _stream = actual as RenderStream < any > | Assertable
2929 const stream =
3030 assertableSymbol in _stream ? _stream [ assertableSymbol ] : _stream
@@ -44,20 +44,24 @@ export const toRerender: MatcherFunction<[options?: NextRenderOptions]> =
4444 pass,
4545 message ( ) {
4646 return (
47- hint +
48- `\n\nExpected component to${ pass ? ' not' : '' } rerender, ` +
47+ `${ hint } \n\nExpected component to${ pass ? ' not' : '' } rerender, ` +
4948 `but it did${ pass ? '' : ' not' } .`
5049 )
5150 } ,
5251 }
5352 }
5453
5554/** to be thrown to "break" test execution and fail it */
56- const failed = { }
55+ const failed = new Error ( )
5756
5857export const toRenderExactlyTimes : MatcherFunction <
5958 [ times : number , options ?: NextRenderOptions ]
60- > = async function ( actual , times , optionsPerRender ) {
59+ > = async function toRenderExactlyTimes (
60+ this : MatcherContext ,
61+ actual ,
62+ times ,
63+ optionsPerRender ,
64+ ) {
6165 const _stream = actual as RenderStream < any > | Assertable
6266 const stream =
6367 assertableSymbol in _stream ? _stream [ assertableSymbol ] : _stream
@@ -70,6 +74,7 @@ export const toRenderExactlyTimes: MatcherFunction<
7074 }
7175 try {
7276 while ( stream . totalRenderCount ( ) < times ) {
77+ // eslint-disable-next-line no-await-in-loop
7378 await stream . waitForNextRender ( options )
7479 }
7580 } catch ( e ) {
@@ -95,8 +100,9 @@ export const toRenderExactlyTimes: MatcherFunction<
95100 pass,
96101 message ( ) {
97102 return (
98- hint +
99- ` Expected component to${ pass ? ' not' : '' } render exactly ${ times } .` +
103+ `${
104+ hint
105+ } Expected component to${ pass ? ' not' : '' } render exactly ${ times } .` +
100106 ` It rendered ${ stream . totalRenderCount ( ) } times.`
101107 )
102108 } ,
0 commit comments