EventEmitterTests.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. define(['utils/EventEmitter'], EventEmitter =>
  14. describe('EventEmitter', function() {
  15. beforeEach(function() {
  16. return (this.eventEmitter = new EventEmitter())
  17. })
  18. it('calls listeners', function() {
  19. const cb1 = sinon.stub()
  20. const cb2 = sinon.stub()
  21. this.eventEmitter.on('foo', cb1)
  22. this.eventEmitter.on('bar', cb2)
  23. this.eventEmitter.trigger('foo')
  24. expect(cb1).to.have.been.called
  25. return expect(cb2).to.not.have.been.called
  26. })
  27. it('calls multiple listeners', function() {
  28. const cb1 = sinon.stub()
  29. const cb2 = sinon.stub()
  30. this.eventEmitter.on('foo', cb1)
  31. this.eventEmitter.on('foo', cb2)
  32. this.eventEmitter.trigger('foo')
  33. expect(cb1).to.have.been.called
  34. return expect(cb2).to.have.been.called
  35. })
  36. it('calls listeners with namespace', function() {
  37. const cb1 = sinon.stub()
  38. const cb2 = sinon.stub()
  39. this.eventEmitter.on('foo', cb1)
  40. this.eventEmitter.on('foo.bar', cb2)
  41. this.eventEmitter.trigger('foo')
  42. expect(cb1).to.have.been.called
  43. return expect(cb2).to.have.been.called
  44. })
  45. it('removes listeners', function() {
  46. const cb = sinon.stub()
  47. this.eventEmitter.on('foo', cb)
  48. this.eventEmitter.off('foo')
  49. this.eventEmitter.trigger('foo')
  50. return expect(cb).to.not.have.been.called
  51. })
  52. it('removes namespaced listeners', function() {
  53. const cb = sinon.stub()
  54. this.eventEmitter.on('foo.bar', cb)
  55. this.eventEmitter.off('foo.bar')
  56. this.eventEmitter.trigger('foo')
  57. return expect(cb).to.not.have.been.called
  58. })
  59. it('does not remove unnamespaced listeners if off called with namespace', function() {
  60. const cb1 = sinon.stub()
  61. const cb2 = sinon.stub()
  62. this.eventEmitter.on('foo', cb1)
  63. this.eventEmitter.on('foo.bar', cb2)
  64. this.eventEmitter.off('foo.bar')
  65. this.eventEmitter.trigger('foo')
  66. expect(cb1).to.have.been.called
  67. return expect(cb2).to.not.have.been.called
  68. })
  69. }))