File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,13 +43,13 @@ export class Reflector {
4343 }
4444
4545 /**
46- * Retrieve metadata for a specified key for a specified set of targets and concat results.
46+ * Retrieve metadata for a specified key for a specified set of targets and merge results.
4747 *
4848 * @param metadataKey lookup key for metadata to retrieve
4949 * @param targets context (decorated objects) to retrieve metadata from
5050 *
5151 */
52- public getAllAndConcat < TResult extends any [ ] = any [ ] , TKey = any > (
52+ public getAllAndMerge < TResult extends any [ ] = any [ ] , TKey = any > (
5353 metadataKey : TKey ,
5454 targets : ( Type < any > | Function ) [ ] ,
5555 ) : TResult {
@@ -64,7 +64,7 @@ export class Reflector {
6464 ...b ,
6565 } ;
6666 }
67- return b ;
67+ return [ a , b ] ;
6868 } ) ;
6969 }
7070
Original file line number Diff line number Diff line change @@ -25,16 +25,33 @@ describe('Reflector', () => {
2525 } ) ;
2626 } ) ;
2727
28- describe ( 'getAllAndConcat ' , ( ) => {
28+ describe ( 'getAllAndMerge ' , ( ) => {
2929 it ( 'should reflect metadata of all targets and concat arrays' , ( ) => {
30+ const key = 'key' ;
31+ const value = 'value' ;
32+ Reflect . defineMetadata ( key , [ value ] , Test ) ;
33+ expect ( reflector . getAllAndMerge ( key , [ Test , Test ] ) ) . to . eql ( [
34+ value ,
35+ value ,
36+ ] ) ;
37+ } ) ;
38+ it ( 'should reflect metadata of all targets and create an array' , ( ) => {
3039 const key = 'key' ;
3140 const value = 'value' ;
3241 Reflect . defineMetadata ( key , value , Test ) ;
33- expect ( reflector . getAllAndConcat ( key , [ Test , Test ] ) ) . to . eql ( [
42+ expect ( reflector . getAllAndMerge ( key , [ Test , Test ] ) ) . to . eql ( [
3443 value ,
3544 value ,
3645 ] ) ;
3746 } ) ;
47+ it ( 'should reflect metadata of all targets and merge an object' , ( ) => {
48+ const key = 'key' ;
49+ const value = { test : 'test' } ;
50+ Reflect . defineMetadata ( key , value , Test ) ;
51+ expect ( reflector . getAllAndMerge ( key , [ Test , Test ] ) ) . to . eql ( {
52+ ...value ,
53+ } ) ;
54+ } ) ;
3855 } ) ;
3956
4057 describe ( 'getAllAndOverride' , ( ) => {
You can’t perform that action at this time.
0 commit comments