@@ -67,21 +67,20 @@ describe('useSearchField hook', () => {
67
67
onSubmit . mockClear ( ) ;
68
68
} ) ;
69
69
70
- it ( 'preventDefault is called for Enter and not Escape' , ( ) => {
70
+ it ( 'preventDefault and stopPropagation are not called for Escape' , ( ) => {
71
71
let { inputProps} = renderSearchHook ( { } ) ;
72
- inputProps . onKeyDown ( event ( 'Enter' ) ) ;
73
- expect ( preventDefault ) . toHaveBeenCalledTimes ( 1 ) ;
74
72
inputProps . onKeyDown ( event ( 'Escape' ) ) ;
75
- expect ( preventDefault ) . toHaveBeenCalledTimes ( 1 ) ;
73
+ expect ( preventDefault ) . toHaveBeenCalledTimes ( 0 ) ;
74
+ expect ( stopPropagation ) . toHaveBeenCalledTimes ( 0 ) ;
76
75
} ) ;
77
76
78
- it ( 'stopPropagation is not called for Escape ' , ( ) => {
79
- let { inputProps} = renderSearchHook ( { } ) ;
80
- inputProps . onKeyDown ( event ( 'Escape ' ) ) ;
81
- expect ( stopPropagation ) . toHaveBeenCalledTimes ( 0 ) ;
77
+ it ( 'preventDefault is not called for Enter if onSubmit is not provided ' , ( ) => {
78
+ let { inputProps} = renderSearchHook ( ) ;
79
+ inputProps . onKeyDown ( event ( 'Enter ' ) ) ;
80
+ expect ( preventDefault ) . toHaveBeenCalledTimes ( 0 ) ;
82
81
} ) ;
83
82
84
- it ( 'onSubmit is called if Enter is pressed ' , ( ) => {
83
+ it ( 'preventDefault and onSubmit are called for Enter if submit is provided ' , ( ) => {
85
84
let { inputProps} = renderSearchHook ( { onSubmit} ) ;
86
85
inputProps . onKeyDown ( event ( 'Enter' ) ) ;
87
86
expect ( onSubmit ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments