Matteo Scandolo | ba0d92e | 2017-03-02 16:47:46 -0800 | [diff] [blame] | 1 | import * as angular from 'angular'; |
| 2 | import 'angular-mocks'; |
| 3 | import 'angular-ui-router'; |
| 4 | import {XosDebouncer, IXosDebouncer} from './debounce.helper'; |
| 5 | |
| 6 | let service: IXosDebouncer; |
| 7 | |
| 8 | describe('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 Scandolo | 968e7f2 | 2017-03-03 11:49:18 -0800 | [diff] [blame] | 25 | const efficientSpy = service.debounce(spy, 500, this, false); |
Matteo Scandolo | ba0d92e | 2017-03-02 16:47:46 -0800 | [diff] [blame] | 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 | |