close.js 1.3 KB

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