File tree 4 files changed +13
-14
lines changed
4 files changed +13
-14
lines changed Original file line number Diff line number Diff line change 1
- let asyncAct
1
+ let asyncAct , consoleErrorMock
2
2
3
3
jest . mock ( 'react-dom/test-utils' , ( ) => ( {
4
4
act : cb => {
@@ -9,11 +9,11 @@ jest.mock('react-dom/test-utils', () => ({
9
9
beforeEach ( ( ) => {
10
10
jest . resetModules ( )
11
11
asyncAct = require ( '../act-compat' ) . asyncAct
12
- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
12
+ consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
13
13
} )
14
14
15
15
afterEach ( ( ) => {
16
- console . error . mockRestore ( )
16
+ consoleErrorMock . mockRestore ( )
17
17
} )
18
18
19
19
test ( '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
2
2
3
3
beforeEach ( ( ) => {
4
4
jest . resetModules ( )
5
5
act = require ( '../pure' ) . act
6
6
asyncAct = require ( '../act-compat' ) . asyncAct
7
7
React = require ( 'react' )
8
- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
8
+ consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
9
9
} )
10
10
11
11
afterEach ( ( ) => {
12
- console . error . mockRestore ( )
12
+ consoleErrorMock . mockRestore ( )
13
13
} )
14
14
15
15
jest . mock ( 'react-dom/test-utils' , ( ) => ( { } ) )
Original file line number Diff line number Diff line change 1
- let asyncAct
1
+ let asyncAct , consoleErrorMock
2
2
3
3
beforeEach ( ( ) => {
4
4
jest . resetModules ( )
5
5
asyncAct = require ( '../act-compat' ) . asyncAct
6
- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
6
+ consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
7
7
} )
8
8
9
9
afterEach ( ( ) => {
10
- console . error . mockRestore ( )
10
+ consoleErrorMock . mockRestore ( )
11
11
} )
12
12
13
13
jest . mock ( 'react-dom/test-utils' , ( ) => ( {
Original file line number Diff line number Diff line change 1
1
import '@testing-library/jest-dom/extend-expect'
2
2
3
+ let consoleErrorMock
4
+
3
5
beforeEach ( ( ) => {
4
6
const originalConsoleError = console . error
5
- jest
7
+ consoleErrorMock = jest
6
8
. spyOn ( console , 'error' )
7
9
. mockImplementation ( ( message , ...optionalParams ) => {
8
10
// Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning
@@ -14,8 +16,5 @@ beforeEach(() => {
14
16
} )
15
17
16
18
afterEach ( ( ) => {
17
- // maybe another test already restore console error mocks
18
- if ( typeof console . error . mockRestore === 'function' ) {
19
- console . error . mockRestore ( )
20
- }
19
+ consoleErrorMock . mockRestore ( )
21
20
} )
You can’t perform that action at this time.
0 commit comments