From 5886be5da947179c72d9280ae1aa74acbef7a73d Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Tue, 12 Mar 2019 18:28:55 -0700 Subject: [PATCH] Add tests. --- test/unit/debounce.html | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/unit/debounce.html b/test/unit/debounce.html index 5d20439147..2d770bb611 100644 --- a/test/unit/debounce.html +++ b/test/unit/debounce.html @@ -38,7 +38,7 @@ suite('enqueueDebouncer & flush', function() { - // NOTE: This is a regression test; the bug it fixed only occured if the + // NOTE: This is a regression test; the bug it fixed only occurred if the // debouncer was flushed before any microtasks run, hence it should be // first in this file test('re-enqueue canceled debouncer', function() { @@ -55,6 +55,16 @@ assert.isTrue(cb.calledOnce); }); + test('flushDebouncers from enqueued debouncer', function(done) { + const cb = sinon.spy(() => flush()); + let db = Debouncer.debounce(null, microTask, cb); + enqueueDebouncer(db); + setTimeout(() => { + assert.isTrue(cb.calledOnce); + done(); + }) + }); + const testEnqueue = (shouldFlush, done) => { const actualOrder = []; const enqueue = (type, {db, cb} = {}) => { @@ -89,6 +99,21 @@ testEnqueue(true, done); }); + test('reentrant flush', function() { + const cb2 = sinon.spy(); + let db2; + const cb1 = sinon.spy(() => { + flush(); + db2 = Debouncer.debounce(null, microTask, cb2); + enqueueDebouncer(db2); + }); + const db1 = Debouncer.debounce(null, microTask, cb1); + enqueueDebouncer(db1); + flush(); + assert.isTrue(cb1.calledOnce); + assert.isTrue(cb2.calledOnce); + }); + }); suite('debounce', function() {