-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for isServiceProvider() util
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
tests/browser/packages/support/services/isServiceProvider.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
|
||
}); | ||
}); |