api-callbacks-registry-spec.js 1.1 KB

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