File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -211,3 +211,30 @@ test('calling `fireEvent` directly works too', () => {
211211 } ) ,
212212 )
213213} )
214+
215+ test ( 'blur/foucs bubbles in react' , ( ) => {
216+ const handleBlur = jest . fn ( )
217+ const handleBubbledBlur = jest . fn ( )
218+ const handleFocus = jest . fn ( )
219+ const handleBubbledFocus = jest . fn ( )
220+ const { container} = render (
221+ < div onBlur = { handleBubbledBlur } onFocus = { handleBubbledFocus } >
222+ < button onBlur = { handleBlur } onFocus = { handleFocus } />
223+ </ div > ,
224+ )
225+ const button = container . firstChild . firstChild
226+
227+ fireEvent . focus ( button )
228+
229+ expect ( handleBlur ) . toHaveBeenCalledTimes ( 0 )
230+ expect ( handleBubbledBlur ) . toHaveBeenCalledTimes ( 0 )
231+ expect ( handleFocus ) . toHaveBeenCalledTimes ( 1 )
232+ expect ( handleBubbledFocus ) . toHaveBeenCalledTimes ( 1 )
233+
234+ fireEvent . blur ( button )
235+
236+ expect ( handleBlur ) . toHaveBeenCalledTimes ( 1 )
237+ expect ( handleBubbledBlur ) . toHaveBeenCalledTimes ( 1 )
238+ expect ( handleFocus ) . toHaveBeenCalledTimes ( 1 )
239+ expect ( handleBubbledFocus ) . toHaveBeenCalledTimes ( 1 )
240+ } )
You can’t perform that action at this time.
0 commit comments