File tree 4 files changed +61
-19
lines changed
4 files changed +61
-19
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"esm/react-router-dom.js" : {
3
- "bundled" : 8076 ,
4
- "minified" : 4865 ,
5
- "gzipped" : 1626 ,
3
+ "bundled" : 8159 ,
4
+ "minified" : 4903 ,
5
+ "gzipped" : 1641 ,
6
6
"treeshaked" : {
7
7
"rollup" : {
8
8
"code" : 453 ,
14
14
}
15
15
},
16
16
"umd/react-router-dom.js" : {
17
- "bundled" : 158978 ,
18
- "minified" : 56593 ,
19
- "gzipped" : 16361
17
+ "bundled" : 159106 ,
18
+ "minified" : 56622 ,
19
+ "gzipped" : 16367
20
20
},
21
21
"umd/react-router-dom.min.js" : {
22
- "bundled" : 95833 ,
23
- "minified" : 33613 ,
24
- "gzipped" : 9925
22
+ "bundled" : 95961 ,
23
+ "minified" : 33642 ,
24
+ "gzipped" : 9929
25
25
}
26
26
}
Original file line number Diff line number Diff line change @@ -13,7 +13,12 @@ function isModifiedEvent(event) {
13
13
*/
14
14
class Link extends React . Component {
15
15
handleClick ( event , history ) {
16
- if ( this . props . onClick ) this . props . onClick ( event ) ;
16
+ try {
17
+ if ( this . props . onClick ) this . props . onClick ( event ) ;
18
+ } catch ( ex ) {
19
+ event . preventDefault ( ) ;
20
+ throw ex ;
21
+ }
17
22
18
23
if (
19
24
! event . defaultPrevented && // onClick prevented default
Original file line number Diff line number Diff line change @@ -276,5 +276,42 @@ describe("A <Link>", () => {
276
276
277
277
expect ( memoryHistory . push ) . toBeCalledTimes ( 0 ) ;
278
278
} ) ;
279
+
280
+ it ( "prevents the default event handler if an error occurs" , ( ) => {
281
+ const memoryHistory = createMemoryHistory ( ) ;
282
+ memoryHistory . push = jest . fn ( ) ;
283
+ const error = new Error ( ) ;
284
+ const clickHandler = ( ) => {
285
+ throw error ;
286
+ } ;
287
+ const mockPreventDefault = jest . fn ( ) ;
288
+ const to = "/the/path?the=query#the-hash" ;
289
+
290
+ renderStrict (
291
+ < Router history = { memoryHistory } >
292
+ < Link to = { to } onClick = { clickHandler } >
293
+ link
294
+ </ Link >
295
+ </ Router > ,
296
+ node
297
+ ) ;
298
+
299
+ console . error = jest . fn ( ) ; // keep console clean. Dunno why the catch doesn't do the job correctly.
300
+ try {
301
+ const a = node . querySelector ( "a" ) ;
302
+ ReactTestUtils . Simulate . click ( a , {
303
+ defaultPrevented : false ,
304
+ preventDefault : mockPreventDefault ,
305
+ button : 1
306
+ } ) ;
307
+ } catch ( e ) {
308
+ expect ( e ) . toBe ( error ) ;
309
+ }
310
+
311
+ console . error . mockRestore ( ) ;
312
+ expect ( clickHandler ) . toThrow ( error ) ;
313
+ expect ( mockPreventDefault ) . toHaveBeenCalled ( ) ;
314
+ expect ( memoryHistory . push ) . toBeCalledTimes ( 0 ) ;
315
+ } ) ;
279
316
} ) ;
280
317
} ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"esm/react-router.js" : {
3
- "bundled" : 23396 ,
4
- "minified" : 13250 ,
5
- "gzipped" : 3680 ,
3
+ "bundled" : 23435 ,
4
+ "minified" : 13241 ,
5
+ "gzipped" : 3679 ,
6
6
"treeshaked" : {
7
7
"rollup" : {
8
8
"code" : 2214 ,
14
14
}
15
15
},
16
16
"umd/react-router.js" : {
17
- "bundled" : 98991 ,
18
- "minified" : 35022 ,
19
- "gzipped" : 11227
17
+ "bundled" : 99032 ,
18
+ "minified" : 35013 ,
19
+ "gzipped" : 11222
20
20
},
21
21
"umd/react-router.min.js" : {
22
- "bundled" : 61594 ,
23
- "minified" : 21423 ,
24
- "gzipped" : 7606
22
+ "bundled" : 61635 ,
23
+ "minified" : 21414 ,
24
+ "gzipped" : 7600
25
25
}
26
26
}
You can’t perform that action at this time.
0 commit comments