more explicit tests for debouncer wait and no-wait behavior

This commit is contained in:
Stefan Grönke 2015-08-01 13:33:40 +02:00 committed by Daniel Freedman
parent 9bef4c057c
commit 8ef7bac6dc

View File

@ -85,10 +85,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
};
window.el1.debounce('foo', cb);
window.el1.debounce('foo', cb, 50);
window.el1.debounce('foo', cb, 100);
setTimeout(function() {
assert.equal(called, 1, 'debounce should be called exactly once');
assert.equal(called, 0, 'callback is not called yet');
}, 50);
setTimeout(function() {
assert.equal(called, 1, 'callback was called exactly once');
done();
}, 200);
@ -140,7 +145,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
test('duplicate debouncer assignment', function(done) {
test('duplicate debouncer assignment (no-wait)', function(done) {
var a, b;
@ -155,7 +160,26 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
assert.equal(a, undefined, 'first debouncer was never fired');
assert.equal(b, 'bar', 'only the second debouncer callback was executed');
done();
}, 100);
});
});
test('duplicate debouncer assignment (wait)', function(done) {
var a, b, delay = 50;
window.el1.debounce('foo', function() {
a = 'foo';
}, delay);
window.el1.debounce('foo', function() {
b = 'bar';
}, delay);
setTimeout(function() {
assert.equal(a, undefined, 'first debouncer was never fired');
assert.equal(b, 'bar', 'only the second debouncer callback was executed');
done();
}, (delay+50));
});