Add debounce (formerly known as job), tests, docs.

This commit is contained in:
Kevin Schaaf
2015-01-20 11:34:18 -08:00
parent 1bc61f3232
commit 5188704708
4 changed files with 243 additions and 14 deletions

View File

@@ -36,10 +36,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
suite('CSS utilities', function() {
test('$$:', function() {
// TODO
});
test('toggleClass', function() {
window.el1.toggleClass('foo-class', true);
@@ -59,6 +55,48 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
suite('debounce', function() {
test('debounce (no-wait)', function(done) {
var called = 0;
var cb = function() {
called++;
};
window.el1.debounce('foo', cb);
window.el1.debounce('foo', cb);
window.el1.debounce('foo', cb);
setTimeout(function() {
assert.equal(called, 1, 'debounce should be called exactly once');
done();
}, 50);
});
test('debounce (wait)', function(done) {
var called = 0;
var now = Date.now();
var cb = function() {
called++;
};
window.el1.debounce('foo', cb);
window.el1.debounce('foo', cb, 100);
window.el1.debounce('foo', cb, 100);
setTimeout(function() {
assert.equal(called, 1, 'debounce should be called exactly once');
assert(Date.now() - now > 100, 'debounce should be called after at least 100ms');
done();
}, 200);
});
});
</script>
</body>
</html>