From 1e574975b3d55e3a79a022b1c58df5b335ff7e5c Mon Sep 17 00:00:00 2001 From: Alin Eugen Deac Date: Sat, 13 Apr 2024 12:30:05 +0200 Subject: [PATCH] Add tests for isServiceProvider() util --- .../services/isServiceProvider.test.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/browser/packages/support/services/isServiceProvider.test.js diff --git a/tests/browser/packages/support/services/isServiceProvider.test.js b/tests/browser/packages/support/services/isServiceProvider.test.js new file mode 100644 index 00000000..30721424 --- /dev/null +++ b/tests/browser/packages/support/services/isServiceProvider.test.js @@ -0,0 +1,44 @@ +import { isServiceProvider, ServiceProvider } from "@aedart/support/services"; + +describe('@aedart/support/services', () => { + describe('isServiceProvider()', () => { + + it('can determine if target is a service provider instance', () => { + + class A {} + + class B { + register() {} + + boot() {} + } + + class C extends B {} + + class D extends ServiceProvider {} + + class E extends D {} + + // ------------------------------------------------------------------------------------ // + + const data = [ + { value: null, expected: false, name: 'Null' }, + { value: [], expected: false, name: 'Array' }, + { value: {}, expected: false, name: 'Object (empty)' }, + { value: new A(), expected: false, name: 'Class A (empty)' }, + + { value: new B(), expected: true, name: 'Class B (custom implementation of service provider)' }, + { value: new C(), expected: true, name: 'Class C (inherits from custom implementation)' }, + { value: new D(null), expected: true, name: 'Class D (inherits from ServiceProvider abstraction)' }, + { value: new E(null), expected: true, name: 'Class E (inherits from a base that inherits from ServiceProvider abstraction)' }, + ]; + + for (const entry of data) { + expect(isServiceProvider(entry.value)) + .withContext(`${entry.name} was expected to ${entry.expected.toString()}`) + .toBe(entry.expected); + } + }); + + }); +}); \ No newline at end of file