Skip to content

Commit

Permalink
add more debouncer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gronke authored and dfreedm committed Dec 9, 2015
1 parent 9b898c2 commit 0206852
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/unit/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,71 @@

});

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>
Expand Down

0 comments on commit 0206852

Please sign in to comment.