| Total Complexity | 7 |
| Complexity/F | 1.17 |
| Lines of Code | 49 |
| Function Count | 6 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | /* eslint-enable describe it sinon */ |
||
| 3 | import expect from 'expect'; |
||
| 4 | import { |
||
| 5 | throttle, debounce |
||
| 6 | } from './../../src/util/throttle'; |
||
| 7 | |||
| 8 | describe('throttle utility function', () => { |
||
| 9 | |||
| 10 | it('Should call a function', () => { |
||
| 11 | const spy = sinon.spy(); |
||
| 12 | const func = throttle(spy, null); |
||
| 13 | |||
| 14 | func(); |
||
| 15 | |||
| 16 | expect(spy.called) |
||
| 17 | .toEqual(true); |
||
| 18 | }); |
||
| 19 | |||
| 20 | it('Should call a function only once', () => { |
||
| 21 | const spy = sinon.spy(); |
||
| 22 | const func = throttle(spy, null); |
||
| 23 | |||
| 24 | for (let i = 0; i < 10; i++) { |
||
| 25 | func(); |
||
| 26 | } |
||
| 27 | |||
| 28 | expect(spy.callCount) |
||
| 29 | .toEqual(1); |
||
| 30 | }); |
||
| 31 | }); |
||
| 32 | |||
| 33 | describe('debounce utility function', () => { |
||
| 34 | |||
| 35 | it('Should call a function after timeout', (done) => { |
||
| 36 | const spy = sinon.spy(); |
||
| 37 | const func = debounce(spy, 100); |
||
| 38 | |||
| 39 | func(); |
||
| 40 | |||
| 41 | expect(spy.called) |
||
| 42 | .toEqual(false); |
||
| 43 | |||
| 44 | setTimeout(() => { |
||
| 45 | expect(spy.called) |
||
| 46 | .toEqual(true); |
||
| 47 | done(); |
||
| 48 | }, 101); |
||
| 49 | }); |
||
| 50 | |||
| 51 | }); |
||
| 52 |