Skip to content

Commit

Permalink
Merge pull request #2 from risen228/fix/205-value-provider-check
Browse files Browse the repository at this point in the history
Fix value provider check
  • Loading branch information
risen228 authored Jul 19, 2024
2 parents a0b782d + 659001b commit 87d27c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/__tests__/global-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ 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 type ValueProvider<T> = {
export function isValueProvider<T>(
provider: Provider<T>,
): provider is ValueProvider<T> {
return (provider as ValueProvider<T>).useValue != null
return Object.prototype.hasOwnProperty.call(provider, 'useValue')
}

0 comments on commit 87d27c3

Please sign in to comment.