close.js
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* global describe:true, beforeEach:true, it:true */
var chan = require('..')
var expect = require('expect.js')
describe('A closed channel', function () {
it(
'should yield an error when attempting to add a value',
function () {
var ch = chan()
ch.close()
ch('foo')(function (err) {
expect(err).to.be.an(Error)
})
}
)
describe('that is has items in the buffer', function () {
it(
'should return `false` when the `done()` method is called',
function () {
var ch = chan(1)
ch('foo')
ch.close()
expect(ch.done()).to.be(false)
}
)
})
describe('that is empty', function () {
it(
'should invoke peding callbacks with empty value',
function () {
var ch = chan()
ch(function (err, value) {
expect(value).to.be(ch.empty)
})
ch.close()
}
)
it(
'should return `true` when the `done()` method is called',
function () {
var ch = chan()
ch.close()
expect(ch.done()).to.be(true)
}
)
it(
'should immediately invoke any callback added with the empty value',
function () {
var ch = chan()
ch.close()
ch(function (err, value) {
expect(value).to.be(ch.empty)
})
}
)
})
})