debuggable-service.spec.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {expect} from 'chai';
  2. import {Service} from './service.js';
  3. import {Debuggable} from '@e22m4u/js-debug';
  4. import {ServiceContainer} from './service-container.js';
  5. import {DebuggableService} from './debuggable-service.js';
  6. describe('DebuggableService', function () {
  7. it('should be instantiated correctly without arguments', function () {
  8. const debuggableService = new DebuggableService();
  9. expect(debuggableService).to.be.an.instanceOf(DebuggableService);
  10. expect(debuggableService).to.be.an.instanceOf(Debuggable);
  11. expect(debuggableService.container).to.be.an.instanceOf(ServiceContainer);
  12. });
  13. it('should accept an existing ServiceContainer', function () {
  14. const container = new ServiceContainer();
  15. const debuggableService = new DebuggableService(container);
  16. expect(debuggableService.container).to.eq(container);
  17. });
  18. it('should inherit the static "kinds" property from Service', function () {
  19. expect(DebuggableService.kinds).to.eql(Service.kinds);
  20. });
  21. it('should pass options to the Debuggable constructor', function () {
  22. const options = {namespace: 'myNamespace'};
  23. const debuggableService = new DebuggableService(undefined, options);
  24. expect(debuggableService.debug.state.nsSegments).to.eql([
  25. 'myNamespace',
  26. 'debuggableService',
  27. ]);
  28. });
  29. describe('service method delegation', function () {
  30. let debuggableService;
  31. beforeEach(function () {
  32. debuggableService = new DebuggableService();
  33. });
  34. it("should delegate the 'container' getter to the internal service's container", function () {
  35. expect(debuggableService.container).to.eq(
  36. debuggableService._service.container,
  37. );
  38. });
  39. it("should delegate the 'getService' getter to the internal service's getService method", function () {
  40. expect(debuggableService.getService).to.eq(
  41. debuggableService._service.getService,
  42. );
  43. });
  44. it("should delegate the 'hasService' getter to the internal service's hasService method", function () {
  45. expect(debuggableService.hasService).to.eq(
  46. debuggableService._service.hasService,
  47. );
  48. });
  49. it("should delegate the 'addService' getter to the internal service's addService method", function () {
  50. expect(debuggableService.addService).to.eq(
  51. debuggableService._service.addService,
  52. );
  53. });
  54. it("should delegate the 'useService' getter to the internal service's useService method", function () {
  55. expect(debuggableService.useService).to.eq(
  56. debuggableService._service.useService,
  57. );
  58. });
  59. it("should delegate the 'setService' getter to the internal service's setService method", function () {
  60. expect(debuggableService.setService).to.eq(
  61. debuggableService._service.setService,
  62. );
  63. });
  64. it("should delegate the 'findService' getter to the internal service's findService method", function () {
  65. expect(debuggableService.findService).to.eq(
  66. debuggableService._service.findService,
  67. );
  68. });
  69. });
  70. });