UNPKG

dojo

Version:

Dojo core is a powerful, lightweight library that makes common tasks quicker and easier. Animate elements, manipulate the DOM, and query with easy CSS syntax, all without sacrificing performance.

53 lines (46 loc) 1 kB
define([ 'intern!object', 'intern/chai!assert', '../../debounce', 'sinon' ], function (registerSuite, assert, debounce, sinon) { registerSuite({ name: 'dojo/debounce', sync: function () { var spy = sinon.spy(); var debouncer = debounce(spy, 100); debouncer(); debouncer(); debouncer(); setTimeout(this.async().callback(function () { assert.equal(spy.callCount, 1); }), 1000); }, async: function () { var spy = sinon.spy(); var debouncer = sinon.spy(debounce(spy, 100)); debouncer(); setTimeout(function () { debouncer(); }, 40); setTimeout(function () { debouncer(); }, 80); setTimeout(function () { debouncer(); }, 120); setTimeout(function () { debouncer(); }, 180); setTimeout(function () { debouncer(); }, 220); setTimeout(function () { debouncer(); }, 350); setTimeout(this.async().callback(function () { assert.ok(spy.callCount < debouncer.callCount); }), 2000); } }); });