Skip to content

Commit

Permalink
Add tests for isServiceProvider() util
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Apr 13, 2024
1 parent 532610d commit 1e57497
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/browser/packages/support/services/isServiceProvider.test.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

});
});

0 comments on commit 1e57497

Please sign in to comment.