File tree Expand file tree Collapse file tree 4 files changed +13
-14
lines changed Expand file tree Collapse file tree 4 files changed +13
-14
lines changed Original file line number Diff line number Diff line change 1- let asyncAct
1+ let asyncAct , consoleErrorMock
22
33jest . mock ( 'react-dom/test-utils' , ( ) => ( {
44 act : cb => {
@@ -9,11 +9,11 @@ jest.mock('react-dom/test-utils', () => ({
99beforeEach ( ( ) => {
1010 jest . resetModules ( )
1111 asyncAct = require ( '../act-compat' ) . asyncAct
12- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
12+ consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
1313} )
1414
1515afterEach ( ( ) => {
16- console . error . mockRestore ( )
16+ consoleErrorMock . mockRestore ( )
1717} )
1818
1919test ( 'async act works when it does not exist (older versions of react)' , async ( ) => {
Original file line number Diff line number Diff line change 1- let act , asyncAct , React
1+ let act , asyncAct , React , consoleErrorMock
22
33beforeEach ( ( ) => {
44 jest . resetModules ( )
55 act = require ( '../pure' ) . act
66 asyncAct = require ( '../act-compat' ) . asyncAct
77 React = require ( 'react' )
8- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
8+ consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
99} )
1010
1111afterEach ( ( ) => {
12- console . error . mockRestore ( )
12+ consoleErrorMock . mockRestore ( )
1313} )
1414
1515jest . mock ( 'react-dom/test-utils' , ( ) => ( { } ) )
Original file line number Diff line number Diff line change 1- let asyncAct
1+ let asyncAct , consoleErrorMock
22
33beforeEach ( ( ) => {
44 jest . resetModules ( )
55 asyncAct = require ( '../act-compat' ) . asyncAct
6- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
6+ consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
77} )
88
99afterEach ( ( ) => {
10- console . error . mockRestore ( )
10+ consoleErrorMock . mockRestore ( )
1111} )
1212
1313jest . mock ( 'react-dom/test-utils' , ( ) => ( {
Original file line number Diff line number Diff line change 11import '@testing-library/jest-dom/extend-expect'
22
3+ let consoleErrorMock
4+
35beforeEach ( ( ) => {
46 const originalConsoleError = console . error
5- jest
7+ consoleErrorMock = jest
68 . spyOn ( console , 'error' )
79 . mockImplementation ( ( message , ...optionalParams ) => {
810 // Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning
@@ -14,8 +16,5 @@ beforeEach(() => {
1416} )
1517
1618afterEach ( ( ) => {
17- // maybe another test already restore console error mocks
18- if ( typeof console . error . mockRestore === 'function' ) {
19- console . error . mockRestore ( )
20- }
19+ consoleErrorMock . mockRestore ( )
2120} )
You can’t perform that action at this time.
0 commit comments