This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This notifies listeners on ready to be used components Closes #1121
- Loading branch information
1 parent
2b541ee
commit 7c4f592
Showing
2 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
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,115 @@ | ||
// tslint:disable: no-implicit-dependencies | ||
import { assert } from 'chai'; | ||
import { TSDI, component, initialize, inject } from '..'; | ||
|
||
describe('TSDI', () => { | ||
let tsdi: TSDI; | ||
|
||
beforeEach(() => { | ||
tsdi = new TSDI(); | ||
}); | ||
|
||
afterEach(() => { | ||
tsdi.close(); | ||
}); | ||
|
||
describe('with initializers', () => { | ||
it('should notify when a component without initializer is ready to be used', (done) => { | ||
@component | ||
class Component {} | ||
tsdi.register(Component); | ||
|
||
tsdi.addLifecycleListener({ | ||
onReady(component: any): void { | ||
assert.instanceOf(component, Component); | ||
done(); | ||
}, | ||
}); | ||
|
||
tsdi.get(Component); | ||
}); | ||
|
||
it('should notify when a component is ready to be used', (done) => { | ||
@component | ||
class Component { | ||
@initialize | ||
protected init(): void { | ||
// | ||
} | ||
} | ||
tsdi.register(Component); | ||
|
||
tsdi.addLifecycleListener({ | ||
onReady(component: any): void { | ||
assert.instanceOf(component, Component); | ||
done(); | ||
}, | ||
}); | ||
|
||
tsdi.get(Component); | ||
}); | ||
|
||
it('should notify when a component with async dependency is ready to be used', (done) => { | ||
@component | ||
class Dependency { | ||
@initialize | ||
protected async init(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
} | ||
tsdi.register(Dependency); | ||
|
||
@component | ||
class Component { | ||
@inject | ||
public readonly dependency!: Dependency; | ||
|
||
@initialize | ||
protected async init(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
} | ||
tsdi.register(Component); | ||
|
||
tsdi.addLifecycleListener({ | ||
onReady(component: any): void { | ||
if (component instanceof Component) { | ||
assert.instanceOf(component, Component); | ||
done(); | ||
} | ||
}, | ||
}); | ||
|
||
tsdi.get(Component); | ||
}); | ||
|
||
it('should notify when a component without initializer but with async dependency is ready to be used', (done) => { | ||
@component | ||
class Dependency { | ||
@initialize | ||
protected async init(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
} | ||
tsdi.register(Dependency); | ||
|
||
@component | ||
class Component { | ||
@inject | ||
public readonly dependency!: Dependency; | ||
} | ||
tsdi.register(Component); | ||
|
||
tsdi.addLifecycleListener({ | ||
onReady(component: any): void { | ||
if (component instanceof Component) { | ||
assert.instanceOf(component, Component); | ||
done(); | ||
} | ||
}, | ||
}); | ||
|
||
tsdi.get(Component); | ||
}); | ||
}); | ||
}); |
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