Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine value provider check if user passes a 'undefined' value #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/__tests__/global-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ test("registers by value provider", () => {
expect(globalContainer.isRegistered(registration.token)).toBeTruthy();
});

test("value provider with 'undefined' value should work fine", () => {
globalContainer.register("Foo", {
useValue: undefined
});
expect(globalContainer.resolve("Foo")).toBe(undefined);
});

test("registers by token provider", () => {
const registration = {
token: "IBar",
Expand Down
2 changes: 1 addition & 1 deletion src/providers/value-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default interface ValueProvider<T> {
export function isValueProvider<T>(
provider: Provider<T>
): provider is ValueProvider<T> {
return (provider as ValueProvider<T>).useValue != undefined;
return Object.prototype.hasOwnProperty.call(provider, "useValue");
}