api-callbacks-registry-spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { expect } from 'chai';
  2. import { CallbacksRegistry } from '../lib/renderer/remote/callbacks-registry';
  3. import { ifdescribe } from './spec-helpers';
  4. const features = process._linkedBinding('electron_common_features');
  5. ifdescribe(features.isRemoteModuleEnabled())('CallbacksRegistry module', () => {
  6. let registry: CallbacksRegistry;
  7. beforeEach(() => {
  8. registry = new CallbacksRegistry();
  9. });
  10. it('adds a callback to the registry', () => {
  11. const cb = () => [1, 2, 3, 4, 5];
  12. const key = registry.add(cb);
  13. expect(key).to.exist('key');
  14. });
  15. it('returns a specified callback if it is in the registry', () => {
  16. const cb = () => [1, 2, 3, 4, 5];
  17. const key = registry.add(cb);
  18. expect(key).to.exist('key');
  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. expect(key).to.exist('key');
  30. registry.remove(key!);
  31. const afterCB = registry.get(key!);
  32. expect(afterCB).to.be.a('function');
  33. expect(afterCB.toString()).to.not.equal(cb.toString());
  34. });
  35. });