File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -592,5 +592,38 @@ if (_.inBrowser) {
592
592
} )
593
593
} )
594
594
595
+ it ( 'support debounce' , function ( done ) {
596
+ var spy = jasmine . createSpy ( )
597
+ var vm = new Vue ( {
598
+ el : el ,
599
+ data : {
600
+ test : 'a'
601
+ } ,
602
+ watch : {
603
+ test : spy
604
+ } ,
605
+ template : '<input v-model="test" debounce="100">'
606
+ } )
607
+ el . firstChild . value = 'b'
608
+ trigger ( el . firstChild , 'input' )
609
+ setTimeout ( function ( ) {
610
+ el . firstChild . value = 'c'
611
+ trigger ( el . firstChild , 'input' )
612
+ } , 10 )
613
+ setTimeout ( function ( ) {
614
+ el . firstChild . value = 'd'
615
+ trigger ( el . firstChild , 'input' )
616
+ } , 20 )
617
+ setTimeout ( function ( ) {
618
+ expect ( spy . calls . count ( ) ) . toBe ( 0 )
619
+ expect ( vm . test ) . toBe ( 'a' )
620
+ } , 30 )
621
+ setTimeout ( function ( ) {
622
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
623
+ expect ( vm . test ) . toBe ( 'd' )
624
+ done ( )
625
+ } , 200 )
626
+ } )
627
+
595
628
} )
596
629
}
Original file line number Diff line number Diff line change @@ -116,4 +116,20 @@ describe('Util - Language Enhancement', function () {
116
116
expect ( desc . enumerable ) . toBe ( true )
117
117
} )
118
118
119
+ it ( 'debounce' , function ( done ) {
120
+ var count = 0
121
+ var fn = _ . debounce ( function ( ) {
122
+ count ++
123
+ } , 100 )
124
+ fn ( )
125
+ setTimeout ( fn , 10 )
126
+ setTimeout ( fn , 20 )
127
+ setTimeout ( function ( ) {
128
+ expect ( count ) . toBe ( 0 )
129
+ } , 30 )
130
+ setTimeout ( function ( ) {
131
+ expect ( count ) . toBe ( 1 )
132
+ done ( )
133
+ } , 200 )
134
+ } )
119
135
} )
You can’t perform that action at this time.
0 commit comments