Skip to content

Commit

Permalink
Merge pull request nestjs#340 from patrickhousley/bugfix/symbol-injec…
Browse files Browse the repository at this point in the history
…tion

fix(core): support symbols
  • Loading branch information
kamilmysliwiec authored Jan 6, 2018
2 parents ceb0ecb + 4359785 commit 4d32bc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/common/utils/shared.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const validatePath = (path): string =>
path.charAt(0) !== '/' ? '/' + path : path;
export const isNil = (obj): boolean => isUndefined(obj) || obj === null;
export const isEmpty = (array): boolean => !(array && array.length > 0);
export const isSymbol = (fn): boolean => typeof fn === 'symbol';
3 changes: 2 additions & 1 deletion src/core/injector/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isNil,
isUndefined,
isString,
isSymbol,
} from '@nestjs/common/utils/shared.utils';
import { RuntimeException } from '../errors/exceptions/runtime.exception';
import { Reflector } from '../services/reflector.service';
Expand Down Expand Up @@ -255,7 +256,7 @@ export class Module {
exportedComponent: CustomFactory | CustomValue | CustomClass,
) {
const provide = exportedComponent.provide;
if (isString(provide)) {
if (isString(provide) || isSymbol(provide)) {
return this._exports.add(provide);
}
this._exports.add(provide.name);
Expand Down
10 changes: 10 additions & 0 deletions src/core/test/injector/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ describe('Module', () => {
module.addExportedComponent({ provide: 'test' } as any);
expect(addCustomExportedComponentSpy.called).to.be.true;
});
it('should support symbols', () => {
const addCustomExportedComponentSpy = sinon.spy(
module,
'addCustomExportedComponent',
);
const symb = Symbol('test');
module.addExportedComponent({ provide: symb } as any);
expect(addCustomExportedComponentSpy.called).to.be.true;
expect((module as any)._exports.has(symb)).to.be.true;
});
});

describe('replace', () => {
Expand Down

0 comments on commit 4d32bc3

Please sign in to comment.