Skip to content

Commit fdc0151

Browse files
committed
unit test for v-model debounce
1 parent 2dee125 commit fdc0151

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/unit/specs/directives/model_spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,5 +592,38 @@ if (_.inBrowser) {
592592
})
593593
})
594594

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+
595628
})
596629
}

test/unit/specs/util/lang_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,20 @@ describe('Util - Language Enhancement', function () {
116116
expect(desc.enumerable).toBe(true)
117117
})
118118

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+
})
119135
})

0 commit comments

Comments
 (0)