-
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.
feat: Add decorator for deregistration of injectables
- Loading branch information
Showing
3 changed files
with
79 additions
and
18 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
39 changes: 39 additions & 0 deletions
39
...e/src/dependency-injection-container/createContainer.decoration-of-deregistration.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,39 @@ | ||
import getInjectable from '../getInjectable/getInjectable'; | ||
import { createContainer } from '../../index'; | ||
import { deregistrationDecoratorToken } from './createContainer'; | ||
|
||
describe('createContainer.decoration-of-deregistration', () => { | ||
describe('given there is decorator for deregistration, when an injectable is deregistered, ', () => { | ||
let someInjectable; | ||
let di; | ||
let deregisterDecoratorMock; | ||
|
||
beforeEach(() => { | ||
di = createContainer(); | ||
|
||
deregisterDecoratorMock = jest.fn(); | ||
|
||
const someDeregistrationDecorator = getInjectable({ | ||
id: 'some-deregistration-decorator', | ||
|
||
instantiate: () => () => deregisterDecoratorMock, | ||
|
||
injectionToken: deregistrationDecoratorToken, | ||
}); | ||
|
||
someInjectable = getInjectable({ | ||
id: 'some-injectable', | ||
instantiate: () => 'irrelevant', | ||
}); | ||
|
||
di.register(someDeregistrationDecorator); | ||
di.register(someInjectable); | ||
}); | ||
|
||
it('when the injectable is deregistered, calls decorator with injectable', () => { | ||
di.deregister(someInjectable); | ||
|
||
expect(deregisterDecoratorMock).toHaveBeenCalledWith(someInjectable); | ||
}); | ||
}); | ||
}); |
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