@@ -45,6 +45,51 @@ describe('Inspector for a class', () => {
45
45
} ) ;
46
46
} ) ;
47
47
48
+ describe ( 'Inspector for a class for its own metadata' , ( ) => {
49
+ /**
50
+ * Define `@classDecorator(spec)`
51
+ * @param spec
52
+ */
53
+ function classDecorator ( spec : object ) : ClassDecorator {
54
+ return ClassDecoratorFactory . createDecorator ( 'test' , spec ) ;
55
+ }
56
+
57
+ @classDecorator ( { x : 1 } )
58
+ class BaseController { }
59
+
60
+ @classDecorator ( { y : 2 } )
61
+ class SubController extends BaseController { }
62
+
63
+ class AnotherController extends BaseController { }
64
+
65
+ it ( 'inspects metadata of a base class' , ( ) => {
66
+ const meta = MetadataInspector . getClassMetadata (
67
+ 'test' ,
68
+ BaseController ,
69
+ true ,
70
+ ) ;
71
+ expect ( meta ) . to . eql ( { x : 1 } ) ;
72
+ } ) ;
73
+
74
+ it ( 'inspects metadata of a sub class' , ( ) => {
75
+ const meta = MetadataInspector . getClassMetadata (
76
+ 'test' ,
77
+ SubController ,
78
+ true ,
79
+ ) ;
80
+ expect ( meta ) . to . eql ( { x : 1 , y : 2 } ) ;
81
+ } ) ;
82
+
83
+ it ( 'inspects metadata of a sub class without override' , ( ) => {
84
+ const meta = MetadataInspector . getClassMetadata (
85
+ 'test' ,
86
+ AnotherController ,
87
+ true ,
88
+ ) ;
89
+ expect ( meta ) . to . be . undefined ( ) ;
90
+ } ) ;
91
+ } ) ;
92
+
48
93
describe ( 'Inspector for instance properties' , ( ) => {
49
94
/**
50
95
* Define `@propertyDecorator(spec)`
@@ -64,6 +109,10 @@ describe('Inspector for instance properties', () => {
64
109
myProp : string ;
65
110
}
66
111
112
+ class AnotherController extends BaseController {
113
+ myProp : string ;
114
+ }
115
+
67
116
it ( 'inspects metadata of all properties of a base class' , ( ) => {
68
117
const meta = MetadataInspector . getAllPropertyMetadata (
69
118
'test' ,
@@ -88,6 +137,23 @@ describe('Inspector for instance properties', () => {
88
137
) ;
89
138
expect ( meta ) . to . eql ( { myProp : { x : 1 , y : 2 } } ) ;
90
139
} ) ;
140
+
141
+ it ( 'inspects own metadata of all properties of a sub class' , ( ) => {
142
+ const meta = MetadataInspector . getAllPropertyMetadata (
143
+ 'test' ,
144
+ AnotherController . prototype ,
145
+ true ,
146
+ ) ;
147
+ expect ( meta ) . to . be . undefined ( ) ;
148
+
149
+ const propertyMeta = MetadataInspector . getPropertyMetadata (
150
+ 'test' ,
151
+ AnotherController . prototype ,
152
+ 'myProp' ,
153
+ true ,
154
+ ) ;
155
+ expect ( propertyMeta ) . to . be . undefined ( ) ;
156
+ } ) ;
91
157
} ) ;
92
158
93
159
describe ( 'Inspector for static properties' , ( ) => {
@@ -109,6 +175,10 @@ describe('Inspector for static properties', () => {
109
175
static myProp : string ;
110
176
}
111
177
178
+ class AnotherController extends BaseController {
179
+ static myProp : string ;
180
+ }
181
+
112
182
it ( 'inspects metadata of all properties of a base class' , ( ) => {
113
183
const meta = MetadataInspector . getAllPropertyMetadata (
114
184
'test' ,
@@ -133,6 +203,23 @@ describe('Inspector for static properties', () => {
133
203
) ;
134
204
expect ( meta ) . to . eql ( { myProp : { x : 1 , y : 2 } } ) ;
135
205
} ) ;
206
+
207
+ it ( 'inspects own metadata of all properties of a sub class' , ( ) => {
208
+ const meta = MetadataInspector . getAllPropertyMetadata (
209
+ 'test' ,
210
+ AnotherController ,
211
+ true ,
212
+ ) ;
213
+ expect ( meta ) . to . be . undefined ( ) ;
214
+
215
+ const propertyMeta = MetadataInspector . getPropertyMetadata (
216
+ 'test' ,
217
+ AnotherController ,
218
+ 'myProp' ,
219
+ true ,
220
+ ) ;
221
+ expect ( propertyMeta ) . to . be . undefined ( ) ;
222
+ } ) ;
136
223
} ) ;
137
224
138
225
describe ( 'Inspector for instance methods' , ( ) => {
@@ -154,6 +241,8 @@ describe('Inspector for instance methods', () => {
154
241
myMethod ( ) { }
155
242
}
156
243
244
+ class AnotherController extends BaseController { }
245
+
157
246
it ( 'inspects metadata of all methods of a base class' , ( ) => {
158
247
const meta = MetadataInspector . getAllMethodMetadata (
159
248
'test' ,
@@ -178,6 +267,23 @@ describe('Inspector for instance methods', () => {
178
267
) ;
179
268
expect ( meta ) . to . eql ( { myMethod : { x : 1 , y : 2 } } ) ;
180
269
} ) ;
270
+
271
+ it ( 'inspects own metadata of all methods of a sub class' , ( ) => {
272
+ const meta = MetadataInspector . getAllMethodMetadata (
273
+ 'test' ,
274
+ AnotherController . prototype ,
275
+ true ,
276
+ ) ;
277
+ expect ( meta ) . to . be . undefined ( ) ;
278
+
279
+ const methodMeta = MetadataInspector . getMethodMetadata (
280
+ 'test' ,
281
+ AnotherController . prototype ,
282
+ 'myMethod' ,
283
+ true ,
284
+ ) ;
285
+ expect ( methodMeta ) . to . be . undefined ( ) ;
286
+ } ) ;
181
287
} ) ;
182
288
183
289
describe ( 'Inspector for static methods' , ( ) => {
@@ -199,6 +305,8 @@ describe('Inspector for static methods', () => {
199
305
static myMethod ( ) { }
200
306
}
201
307
308
+ class AnotherController extends BaseController { }
309
+
202
310
it ( 'inspects metadata of all methods of a base class' , ( ) => {
203
311
const meta = MetadataInspector . getAllMethodMetadata ( 'test' , BaseController ) ;
204
312
expect ( meta ) . to . eql ( { myMethod : { x : 1 } } ) ;
@@ -217,6 +325,29 @@ describe('Inspector for static methods', () => {
217
325
const meta = MetadataInspector . getAllMethodMetadata ( 'test' , SubController ) ;
218
326
expect ( meta ) . to . eql ( { myMethod : { x : 1 , y : 2 } } ) ;
219
327
} ) ;
328
+
329
+ it ( 'inspects own metadata of all methods of a sub class' , ( ) => {
330
+ const meta = MetadataInspector . getAllMethodMetadata (
331
+ 'test' ,
332
+ AnotherController ,
333
+ true ,
334
+ ) ;
335
+ expect ( meta ) . to . be . undefined ( ) ;
336
+
337
+ const methodMeta = MetadataInspector . getMethodMetadata (
338
+ 'test' ,
339
+ AnotherController ,
340
+ 'myMethod' ,
341
+ true ,
342
+ ) ;
343
+ expect ( methodMeta ) . to . be . undefined ( ) ;
344
+
345
+ const inherited = MetadataInspector . getAllMethodMetadata (
346
+ 'test' ,
347
+ AnotherController ,
348
+ ) ;
349
+ expect ( inherited ) . to . eql ( { myMethod : { x : 1 } } ) ;
350
+ } ) ;
220
351
} ) ;
221
352
222
353
describe ( 'Inspector for parameters of an instance method' , ( ) => {
@@ -245,6 +376,8 @@ describe('Inspector for parameters of an instance method', () => {
245
376
) { }
246
377
}
247
378
379
+ class AnotherController extends BaseController { }
380
+
248
381
it ( 'inspects metadata of all parameters of a method of the base class' , ( ) => {
249
382
const meta = MetadataInspector . getAllParameterMetadata (
250
383
'test' ,
@@ -272,6 +405,31 @@ describe('Inspector for parameters of an instance method', () => {
272
405
) ;
273
406
expect ( meta ) . to . eql ( { x : 1 , y : 2 } ) ;
274
407
} ) ;
408
+
409
+ it ( 'inspects own metadata of all method parameters of a sub class' , ( ) => {
410
+ const meta = MetadataInspector . getAllParameterMetadata (
411
+ 'test' ,
412
+ AnotherController . prototype ,
413
+ 'myMethod' ,
414
+ true ,
415
+ ) ;
416
+ expect ( meta ) . to . be . undefined ( ) ;
417
+
418
+ const paramsMeta = MetadataInspector . getParameterMetadata (
419
+ 'test' ,
420
+ AnotherController . prototype ,
421
+ 'myMethod' ,
422
+ 0 ,
423
+ true ,
424
+ ) ;
425
+ expect ( paramsMeta ) . to . be . undefined ( ) ;
426
+
427
+ const inherited = MetadataInspector . getAllMethodMetadata (
428
+ 'test' ,
429
+ AnotherController . prototype ,
430
+ ) ;
431
+ expect ( inherited ) . to . eql ( { myMethod : [ { x : 1 } , undefined ] } ) ;
432
+ } ) ;
275
433
} ) ;
276
434
277
435
describe ( 'Inspector for parameters of a static method' , ( ) => {
@@ -300,6 +458,8 @@ describe('Inspector for parameters of a static method', () => {
300
458
) { }
301
459
}
302
460
461
+ class AnotherController extends BaseController { }
462
+
303
463
it ( 'inspects metadata of all parameters of a method of the base class' , ( ) => {
304
464
const meta = MetadataInspector . getAllParameterMetadata (
305
465
'test' ,
@@ -327,6 +487,31 @@ describe('Inspector for parameters of a static method', () => {
327
487
) ;
328
488
expect ( meta ) . to . eql ( { x : 1 , y : 2 } ) ;
329
489
} ) ;
490
+
491
+ it ( 'inspects own metadata of all method parameters of a sub class' , ( ) => {
492
+ const meta = MetadataInspector . getAllParameterMetadata (
493
+ 'test' ,
494
+ AnotherController ,
495
+ 'myMethod' ,
496
+ true ,
497
+ ) ;
498
+ expect ( meta ) . to . be . undefined ( ) ;
499
+
500
+ const paramsMeta = MetadataInspector . getParameterMetadata (
501
+ 'test' ,
502
+ AnotherController ,
503
+ 'myMethod' ,
504
+ 0 ,
505
+ true ,
506
+ ) ;
507
+ expect ( paramsMeta ) . to . be . undefined ( ) ;
508
+
509
+ const inherited = MetadataInspector . getAllMethodMetadata (
510
+ 'test' ,
511
+ AnotherController ,
512
+ ) ;
513
+ expect ( inherited ) . to . eql ( { myMethod : [ { x : 1 } , undefined ] } ) ;
514
+ } ) ;
330
515
} ) ;
331
516
332
517
describe ( 'Inspector for parameters of a constructor' , ( ) => {
0 commit comments