@@ -605,6 +605,49 @@ describe('Select.Basic', () => {
605605 jest . useRealTimers ( ) ;
606606 } ) ;
607607
608+ describe ( 'should call handleSearch twice on search and blur' , ( ) => {
609+ injectRunAllTimers ( jest ) ;
610+
611+ beforeEach ( ( ) => {
612+ jest . useFakeTimers ( ) ;
613+ } ) ;
614+
615+ afterEach ( ( ) => {
616+ jest . useRealTimers ( ) ;
617+ } ) ;
618+
619+ it ( 'multiple mode should call handleSearch twice on search and blur' , async ( ) => {
620+ const handleSearch = jest . fn ( ) ;
621+ const { container } = render (
622+ < Select showSearch onSearch = { handleSearch } mode = "multiple" >
623+ < Option value = "1" > 1</ Option >
624+ < Option value = "2" > 2</ Option >
625+ </ Select > ,
626+ ) ;
627+ fireEvent . change ( container . querySelector ( 'input' ) ! , { target : { value : '1' } } ) ;
628+ // 模拟失去焦点(blur)事件
629+ fireEvent . blur ( container . querySelector ( 'input' ) ) ;
630+ jest . runAllTimers ( ) ;
631+ expect ( handleSearch ) . toHaveBeenCalledTimes ( 2 ) ;
632+ jest . useRealTimers ( ) ;
633+ } ) ;
634+
635+ it ( 'not multiple mode should call handleSearch twice on search and blur' , async ( ) => {
636+ const handleSearch = jest . fn ( ) ;
637+ const { container } = render (
638+ < Select showSearch onSearch = { handleSearch } >
639+ < Option value = "1" > 1</ Option >
640+ < Option value = "2" > 2</ Option >
641+ </ Select > ,
642+ ) ;
643+ fireEvent . change ( container . querySelector ( 'input' ) ! , { target : { value : '1' } } ) ;
644+ fireEvent . blur ( container . querySelector ( 'input' ) ) ;
645+ jest . runAllTimers ( ) ;
646+ expect ( handleSearch ) . toHaveBeenCalledTimes ( 2 ) ;
647+ jest . useRealTimers ( ) ;
648+ } ) ;
649+ } ) ;
650+
608651 it ( 'should render 0 as text properly' , ( ) => {
609652 const data = [
610653 { text : 0 , value : '=0' } ,
0 commit comments