blob: 1c47dbd63d9b9f75452d5c1e5f7d3efdacf4bad9 [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');
25 const efficientSpy = service.debounce(spy, 500, false);
26 /* 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