Skip to content

Commit

Permalink
fix: aliasTo should match container.resolve
Browse files Browse the repository at this point in the history
where symbol can be used for name
  • Loading branch information
zb-sj committed Oct 12, 2023
1 parent 983935b commit 8c902de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/__tests__/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@ describe('registrations', () => {
})

describe('aliasTo', () => {
it('returns the aliased dependency', () => {
it('returns the string aliased dependency', () => {
container.register({ val: asValue(123), aliasVal: aliasTo('val') })
expect(container.resolve('aliasVal')).toBe(123)
})

it('returns the symbol aliased dependency', () => {
const symbol = Symbol()
container.register({ [symbol]: asValue(123), aliasVal: aliasTo(symbol) })
expect(container.resolve('aliasVal')).toBe(123)
})
})
})
6 changes: 4 additions & 2 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ export function asClass<T = {}>(
/**
* Resolves to the specified registration.
*/
export function aliasTo<T>(name: string): Resolver<T> {
export function aliasTo<T>(
...args: Parameters<AwilixContainer['resolve']>
): Resolver<T> {
return {
resolve(container) {
return container.resolve(name)
return container.resolve(...args)
},
}
}
Expand Down

0 comments on commit 8c902de

Please sign in to comment.