Skip to content

Commit

Permalink
more explicit tests for debouncer wait and no-wait behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
gronke authored and dfreedm committed Dec 9, 2015
1 parent 9bef4c0 commit 8ef7bac
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions test/unit/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@
};

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);

Expand Down Expand Up @@ -140,7 +145,7 @@

});

test('duplicate debouncer assignment', function(done) {
test('duplicate debouncer assignment (no-wait)', function(done) {

var a, b;

Expand All @@ -155,7 +160,26 @@
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));

});

Expand Down

0 comments on commit 8ef7bac

Please sign in to comment.