UNPKG

angular-ui-bootstrap-2.0

Version:

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/angular-ui/bootstrap?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://secure.travis-ci.org/angular-ui/bootstrap.svg)](http://travis-

49 lines (35 loc) 1.07 kB
describe('$$debounce', function() { var $$debounce, $timeout, debouncedFunction, i, args; beforeEach(module('ui.bootstrap.debounce')); beforeEach(inject(function(_$$debounce_, _$timeout_) { $$debounce = _$$debounce_; $timeout = _$timeout_; i = 0; debouncedFunction = $$debounce(function() { args = Array.prototype.slice.call(arguments); i++; }, 100); })); it('should function like a $timeout when called once during timeout', function() { debouncedFunction(); $timeout.flush(50); expect(i).toBe(0); $timeout.flush(50); expect(i).toBe(1); }); it('should only execute 100ms after last call when called twice', function() { debouncedFunction(); $timeout.flush(50); expect(i).toBe(0); debouncedFunction(); $timeout.flush(50); expect(i).toBe(0); $timeout.flush(50); expect(i).toBe(1); }); it('should properly pass arguments to debounced function', function() { debouncedFunction(1, 2, 3); $timeout.flush(100); expect(args).toEqual([1, 2, 3]); }); });