| Total Complexity | 19 |
| Complexity/F | 1.73 |
| Lines of Code | 48 |
| Function Count | 11 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | /* eslint-env mocha */ |
||
| 3 | var Sinon = require('sinon') |
||
| 4 | var Chai = require('chai') |
||
| 5 | var expect = Chai.expect |
||
| 6 | var throttle = require('../../../../lib').Concurrent.throttle |
||
| 7 | |||
| 8 | describe('Integration', function () { |
||
| 9 | describe('/concurrent', function () { |
||
| 10 | describe('/timeout.js', function () { |
||
| 11 | describe('.throttle', function () { |
||
| 12 | var clock |
||
| 13 | |||
| 14 | beforeEach(function () { |
||
| 15 | clock = Sinon.useFakeTimers() |
||
| 16 | }) |
||
| 17 | |||
| 18 | afterEach(function () { |
||
| 19 | clock.restore() |
||
| 20 | }) |
||
| 21 | |||
| 22 | it('creates promise that resolves after passed time if it resolved too fast', function () { |
||
| 23 | var promise = Promise.resolve() |
||
| 24 | var stub = Sinon.stub() |
||
| 25 | var throttled = throttle(promise, 10).then(stub) |
||
| 26 | expect(stub.callCount).to.eq(0) |
||
| 27 | clock.next() |
||
| 28 | return throttled |
||
| 29 | .then(function () { |
||
| 30 | expect(stub.callCount).to.eq(1) |
||
| 31 | }) |
||
| 32 | }) |
||
| 33 | |||
| 34 | it('doesn\'t slow down promise that takes longer that throttle time', function () { |
||
| 35 | var promise = new Promise(function (resolve) { |
||
| 36 | setTimeout(resolve, 30) |
||
| 37 | }) |
||
| 38 | var stub = Sinon.stub() |
||
| 39 | var throttled = throttle(promise, 10).then(stub) |
||
| 40 | expect(stub.callCount).to.eq(0) |
||
| 41 | clock.tick(30) |
||
| 42 | return throttled |
||
| 43 | .then(function () { |
||
| 44 | expect(stub.callCount).to.eq(1) |
||
| 45 | }) |
||
| 46 | }) |
||
| 47 | }) |
||
| 48 | }) |
||
| 49 | }) |
||
| 50 | }) |
||
| 51 |