api-callbacks-registry-spec.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const chai = require('chai')
  2. const dirtyChai = require('dirty-chai')
  3. const { expect } = chai
  4. chai.use(dirtyChai)
  5. const CallbacksRegistry = require('../lib/renderer/callbacks-registry')
  6. describe('CallbacksRegistry module', () => {
  7. let registry = null
  8. beforeEach(() => {
  9. registry = new CallbacksRegistry()
  10. })
  11. it('adds a callback to the registry', () => {
  12. const cb = () => [1, 2, 3, 4, 5]
  13. const key = registry.add(cb)
  14. expect(key).to.exist()
  15. })
  16. it('returns a specified callback if it is in the registry', () => {
  17. const cb = () => [1, 2, 3, 4, 5]
  18. const key = registry.add(cb)
  19. const callback = registry.get(key)
  20. expect(callback.toString()).equal(cb.toString())
  21. })
  22. it('returns an empty function if the cb doesnt exist', () => {
  23. const callback = registry.get(1)
  24. expect(callback).to.be.a('function')
  25. })
  26. it('removes a callback to the registry', () => {
  27. const cb = () => [1, 2, 3, 4, 5]
  28. const key = registry.add(cb)
  29. registry.remove(key)
  30. const afterCB = registry.get(key)
  31. expect(afterCB).to.be.a('function')
  32. expect(afterCB.toString()).to.not.equal(cb.toString())
  33. })
  34. })