UNPKG

@kiwicom/smart-faq

Version:

28 lines (26 loc) 726 B
"use strict"; var _functionUtils = require("../functionUtils"); // @flow describe('functionUtils', function () { describe('debounce', function () { var fn = jest.fn(); var time = 200; var debouncedFn = (0, _functionUtils.debounce)(fn, time); beforeEach(function () { jest.resetAllMocks(); }); it('debounces when time smaller than timeout', function () { debouncedFn(); debouncedFn(); debouncedFn(); expect(fn.mock.calls).toHaveLength(0); }); it('debounces when time greater than timeout', function (done) { debouncedFn(); setTimeout(function () { expect(fn.mock.calls).toHaveLength(1); done(); }, time + 10); }); }); });