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 ,
7
7
} from '@testing-library/react-render-stream'
8
8
// explicitly imported the symbol from the internal file
9
9
// this will bundle the `Symbol.for` call twice, but we keep it private
@@ -24,7 +24,7 @@ export interface RenderStreamMatchers<R = void, T = {}> {
24
24
}
25
25
26
26
export const toRerender : MatcherFunction < [ options ?: NextRenderOptions ] > =
27
- async function ( actual , options ) {
27
+ async function toRerender ( this : MatcherContext , actual , options ) {
28
28
const _stream = actual as RenderStream < any > | Assertable
29
29
const stream =
30
30
assertableSymbol in _stream ? _stream [ assertableSymbol ] : _stream
@@ -44,20 +44,24 @@ export const toRerender: MatcherFunction<[options?: NextRenderOptions]> =
44
44
pass,
45
45
message ( ) {
46
46
return (
47
- hint +
48
- `\n\nExpected component to${ pass ? ' not' : '' } rerender, ` +
47
+ `${ hint } \n\nExpected component to${ pass ? ' not' : '' } rerender, ` +
49
48
`but it did${ pass ? '' : ' not' } .`
50
49
)
51
50
} ,
52
51
}
53
52
}
54
53
55
54
/** to be thrown to "break" test execution and fail it */
56
- const failed = { }
55
+ const failed = new Error ( )
57
56
58
57
export const toRenderExactlyTimes : MatcherFunction <
59
58
[ times : number , options ?: NextRenderOptions ]
60
- > = async function ( actual , times , optionsPerRender ) {
59
+ > = async function toRenderExactlyTimes (
60
+ this : MatcherContext ,
61
+ actual ,
62
+ times ,
63
+ optionsPerRender ,
64
+ ) {
61
65
const _stream = actual as RenderStream < any > | Assertable
62
66
const stream =
63
67
assertableSymbol in _stream ? _stream [ assertableSymbol ] : _stream
@@ -70,6 +74,7 @@ export const toRenderExactlyTimes: MatcherFunction<
70
74
}
71
75
try {
72
76
while ( stream . totalRenderCount ( ) < times ) {
77
+ // eslint-disable-next-line no-await-in-loop
73
78
await stream . waitForNextRender ( options )
74
79
}
75
80
} catch ( e ) {
@@ -95,8 +100,9 @@ export const toRenderExactlyTimes: MatcherFunction<
95
100
pass,
96
101
message ( ) {
97
102
return (
98
- hint +
99
- ` Expected component to${ pass ? ' not' : '' } render exactly ${ times } .` +
103
+ `${
104
+ hint
105
+ } Expected component to${ pass ? ' not' : '' } render exactly ${ times } .` +
100
106
` It rendered ${ stream . totalRenderCount ( ) } times.`
101
107
)
102
108
} ,
0 commit comments