@@ -252,6 +252,14 @@ function resultWithMatches(title: string, matches: string[]): IFindItem[] {
252252 ]
253253}
254254
255+ let expectedConsoleError : ReturnType < typeof vi . spyOn > | undefined
256+
257+ function muteExpectedConsoleError ( ) {
258+ expectedConsoleError ?. mockRestore ( )
259+ expectedConsoleError = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => undefined )
260+ return expectedConsoleError
261+ }
262+
255263describe ( 'FindPage search state' , ( ) => {
256264 beforeEach ( ( ) => {
257265 vi . useFakeTimers ( )
@@ -276,11 +284,14 @@ describe('FindPage search state', () => {
276284 } )
277285
278286 afterEach ( ( ) => {
287+ expectedConsoleError ?. mockRestore ( )
288+ expectedConsoleError = undefined
279289 cleanup ( )
280290 vi . useRealTimers ( )
281291 } )
282292
283293 it ( 'stops loading and shows an error when findBy rejects' , async ( ) => {
294+ const consoleError = muteExpectedConsoleError ( )
284295 mocks . actions . findBy . mockRejectedValueOnce ( new Error ( 'boom' ) )
285296 render ( < FindPage /> )
286297
@@ -294,6 +305,7 @@ describe('FindPage search state', () => {
294305
295306 expect ( screen . getByText ( 'boom' ) ) . toBeTruthy ( )
296307 expect ( screen . queryByTestId ( 'loader' ) ) . toBeNull ( )
308+ expect ( consoleError ) . toHaveBeenCalledWith ( 'findBy failed' , expect . any ( Error ) )
297309 } )
298310
299311 it ( 'does not show the loader while a new search is only waiting for debounce' , async ( ) => {
@@ -592,6 +604,7 @@ describe('FindPage search state', () => {
592604 } )
593605
594606 it ( 'refreshes displayed results when replace all fails' , async ( ) => {
607+ const consoleError = muteExpectedConsoleError ( )
595608 mocks . actions . findBy . mockResolvedValueOnce ( result ( 'first-title' , 'abc' ) ) . mockResolvedValueOnce ( [ ] )
596609 mocks . actions . findReplaceAll . mockRejectedValueOnce ( new Error ( 'write failed' ) )
597610 render ( < FindPage /> )
@@ -615,6 +628,7 @@ describe('FindPage search state', () => {
615628 expect . objectContaining ( { message : 'write failed' } ) ,
616629 )
617630 expect ( mocks . actions . findBy ) . toHaveBeenCalledTimes ( 2 )
631+ expect ( consoleError ) . toHaveBeenCalledWith ( 'findReplaceAll failed' , expect . any ( Error ) )
618632 } )
619633
620634 it ( 'refreshes displayed results when replace all finds nothing in current content' , async ( ) => {
0 commit comments