add more debouncer tests

This commit is contained in:
Stefan Grönke 2015-07-30 20:17:35 +02:00 committed by Daniel Freedman
parent 9b898c25cc
commit 0206852575

View File

@ -94,6 +94,71 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
test('debounce flushing', function(done) {
var called = 0;
var cb = function() {
called++;
};
window.el1.debounce('foo', cb);
window.el1.flushDebouncer('foo');
window.el1.debounce('foo', cb);
setTimeout(function() {
assert.equal(called, 2, 'debounce should be called twice');
done();
}, 100);
});
test('debounce state', function(done) {
window.el1.debounce('foo', function() {
assert.equal(window.el1.isDebouncerActive('foo'), false, 'debouncer is inactive after resolution');
done();
});
assert.equal(window.el1.isDebouncerActive('foo'), true, 'debouncer is active immediately after triggering');
});
test('debounce cancelling', function(done) {
var triggered = false;
window.el1.debounce('foo', function() {
triggered = true;
});
window.el1.cancelDebouncer('foo');
assert.equal(window.el1.isDebouncerActive('foo'), false, 'debouncer is inactive after cancelling');
setTimeout(function() {
assert.equal(triggered, false, 'debounce never fired');
done();
}, 100);
});
test('duplicate debouncer assignment', function(done) {
var a, b;
window.el1.debounce('foo', function() {
a = 'foo';
});
window.el1.debounce('foo', function() {
b = 'bar';
});
setTimeout(function() {
assert.equal(a, undefined, 'first debouncer was never fired');
assert.equal(b, 'bar', 'only the second debouncer callback was executed');
done();
}, 100);
});
});
</script>