mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Add debounce (formerly known as job), tests, docs.
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user