Completed
Push — dev ( d30456...4fd03f )
by Fike
33s
created

test/suites/integration/concurrent/timeout.throttle.spec.js   A

Complexity

Total Complexity 19
Complexity/F 1.73

Size

Lines of Code 48
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 48
rs 10
wmc 19
mnd 0
bc 11
fnc 11
bpm 1
cpm 1.7272
noi 0
1
/* eslint-env mocha */
2
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