@@ -2,6 +2,7 @@ import React from 'react';
2
2
3
3
import { mount } from 'enzyme' ;
4
4
import { defaultRegistry } from 'react-sweet-state' ;
5
+ import { act } from 'react-dom/test-utils' ;
5
6
6
7
import { LinkProps } from '../../../../common/types' ;
7
8
import { Router } from '../../../../controllers/router' ;
@@ -36,6 +37,15 @@ const baseClickEvent = {
36
37
const newPath = '/my-new-path' ;
37
38
const eventModifiers = [ [ 'metaKey' ] , [ 'altKey' ] , [ 'ctrlKey' ] , [ 'shiftKey' ] ] ;
38
39
40
+ // https://github.com/facebook/jest/pull/5267#issuecomment-356605468
41
+ const withoutConsoleError = ( fn : ( ) => void ) => ( ) => {
42
+ const consoleError = jest
43
+ . spyOn < Console , 'error' > ( console , 'error' )
44
+ . mockImplementation ( ( ) => undefined ) ;
45
+ fn ( ) ;
46
+ consoleError . mockRestore ( ) ;
47
+ } ;
48
+
39
49
describe ( '<Link />' , ( ) => {
40
50
const mountInRouter = (
41
51
children : LinkProps [ 'children' ] ,
@@ -240,7 +250,7 @@ describe('<Link />', () => {
240
250
params : { id : '1' } ,
241
251
query : { foo : 'bar' } ,
242
252
} ) ;
243
- await Promise . resolve ( ) ;
253
+ await act ( ( ) => Promise . resolve ( ) ) ;
244
254
const component = wrapper . find ( 'Link' ) ;
245
255
246
256
component . simulate ( 'click' , baseClickEvent ) ;
@@ -257,7 +267,11 @@ describe('<Link />', () => {
257
267
} ) ;
258
268
259
269
it ( 'should error if required route parameters are missing' , ( ) => {
260
- expect ( ( ) => mountInRouter ( 'my link' , { to : route } ) ) . toThrow ( ) ;
270
+ expect (
271
+ withoutConsoleError ( ( ) => {
272
+ mountInRouter ( 'my link' , { to : route } ) ;
273
+ } )
274
+ ) . toThrow ( ) ;
261
275
} ) ;
262
276
} ) ;
263
277
0 commit comments