diff --git a/test/unit/utils.html b/test/unit/utils.html index bebd5ca94d..9e142d8935 100644 --- a/test/unit/utils.html +++ b/test/unit/utils.html @@ -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); + + }); + });