blob: e04b11edb44b366889e86166baf6b0bd6a54cbbc [file] [log] [blame]
Matteo Scandoloba0d92e2017-03-02 16:47:46 -08001import * as angular from 'angular';
2import 'angular-mocks';
3import 'angular-ui-router';
4import {XosDebouncer, IXosDebouncer} from './debounce.helper';
5
6let service: IXosDebouncer;
7
8describe('The XosDebouncer service', () => {
9
10 beforeEach(() => {
11 angular
12 .module('test', ['toastr'])
13 .service('XosDebouncer', XosDebouncer);
14 angular.mock.module('test');
15 });
16
17 beforeEach(angular.mock.inject((
18 XosDebouncer: IXosDebouncer,
19 ) => {
20 service = XosDebouncer;
21 }));
22
23 it('should call a function only after it has not been called for 500ms', (done) => {
24 const spy = jasmine.createSpy('fn');
Matteo Scandolo968e7f22017-03-03 11:49:18 -080025 const efficientSpy = service.debounce(spy, 500, this, false);
Matteo Scandoloba0d92e2017-03-02 16:47:46 -080026 /* tslint:disable */
27 efficientSpy();
28 efficientSpy();
29 /* tslint:enable */
30 expect(spy).not.toHaveBeenCalled();
31 setTimeout(() => {
32 expect(spy).toHaveBeenCalled();
33 done();
34 }, 600);
35 });
36});
37