-
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: Implement checking for if "alias-has-registrations"
This permits eg. creation of specialized test utils where default stubs are registered but only if no other matching registrations are present.
- Loading branch information
Showing
4 changed files
with
104 additions
and
3 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
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
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
91 changes: 91 additions & 0 deletions
91
packages/injectable/core/src/scenarios/alias-has-registrations.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,91 @@ | ||
import getInjectable from '../getInjectable/getInjectable'; | ||
import createContainer from '../dependency-injection-container/createContainer'; | ||
import getInjectionToken from '../getInjectionToken/getInjectionToken'; | ||
|
||
describe('alias-has-registrations', () => { | ||
let di; | ||
|
||
beforeEach(() => { | ||
di = createContainer('irrelevant'); | ||
}); | ||
|
||
describe('given an injectable with or without an injection token', () => { | ||
let someInjectable; | ||
let someInjectionToken; | ||
|
||
beforeEach(() => { | ||
someInjectionToken = getInjectionToken({ | ||
id: 'some-injection-token', | ||
}); | ||
|
||
someInjectable = getInjectable({ | ||
id: 'some-injectable', | ||
instantiate: () => 'irrelevant', | ||
injectionToken: someInjectionToken, | ||
}); | ||
}); | ||
|
||
it('given registered, when checking if the token has registrations, it does', () => { | ||
di.register(someInjectable); | ||
|
||
const tokenHasRegistrations = di.hasRegistrations(someInjectionToken); | ||
|
||
expect(tokenHasRegistrations).toBe(true); | ||
}); | ||
|
||
it('but not registered, when checking if the token has registrations, it does not', () => { | ||
// Note: no registration. | ||
// di.register(someInjectable); | ||
|
||
const injectableHasRegistrations = | ||
di.hasRegistrations(someInjectionToken); | ||
|
||
expect(injectableHasRegistrations).toBe(false); | ||
}); | ||
|
||
it('given registered, when checking if the injectable has registrations, it does', () => { | ||
di.register(someInjectable); | ||
|
||
const injectableHasRegistrations = di.hasRegistrations(someInjectable); | ||
|
||
expect(injectableHasRegistrations).toBe(true); | ||
}); | ||
|
||
it('but not registered, when checking if the injectable has registrations, it does not', () => { | ||
// Note: no registration. | ||
// di.register(someInjectable); | ||
|
||
const injectableHasRegistrations = di.hasRegistrations(someInjectable); | ||
|
||
expect(injectableHasRegistrations).toBe(false); | ||
}); | ||
|
||
it('given registered, but deregistered, when checking if the token has registrations, it does not', () => { | ||
di.register(someInjectable); | ||
di.deregister(someInjectable); | ||
|
||
const injectableHasRegistrations = | ||
di.hasRegistrations(someInjectionToken); | ||
|
||
expect(injectableHasRegistrations).toBe(false); | ||
}); | ||
|
||
it('but not registered, when checking if the injectable has registrations, it does not', () => { | ||
// Note: no registration. | ||
// di.register(someInjectable); | ||
|
||
const injectableHasRegistrations = di.hasRegistrations(someInjectable); | ||
|
||
expect(injectableHasRegistrations).toBe(false); | ||
}); | ||
|
||
it('given registered, but deregistered, when checking if the injectable has registrations, it does not', () => { | ||
di.register(someInjectable); | ||
di.deregister(someInjectable); | ||
|
||
const injectableHasRegistrations = di.hasRegistrations(someInjectable); | ||
|
||
expect(injectableHasRegistrations).toBe(false); | ||
}); | ||
}); | ||
}); |