@@ -58,14 +58,14 @@ describe("decorators", () => {
58
58
generatePublicApiFromExportedDecorator ( ) ;
59
59
const actualResult : any = $injector . publicApi . __modules__ [ moduleName ] [ propertyName ] ( ) ;
60
60
assert . deepEqual ( actualResult , expectedResult ) ;
61
- } ) ;
61
+ } ) ;
62
62
63
63
it ( `passes correct arguments to original function, when argument type is: ${ _ . isArray ( expectedResult ) ? "array" : typeof ( expectedResult ) } ` , ( ) => {
64
64
$injector . register ( moduleName , { propertyName : ( arg : any ) => arg } ) ;
65
65
generatePublicApiFromExportedDecorator ( ) ;
66
66
const actualResult : any = $injector . publicApi . __modules__ [ moduleName ] [ propertyName ] ( expectedResult ) ;
67
67
assert . deepEqual ( actualResult , expectedResult ) ;
68
- } ) ;
68
+ } ) ;
69
69
} ) ;
70
70
71
71
it ( "returns Promise, which is resolved to correct value (function without arguments)" , ( done : mocha . Done ) => {
@@ -202,7 +202,7 @@ describe("decorators", () => {
202
202
generatePublicApiFromExportedDecorator ( ) ;
203
203
assert . throws ( ( ) => $injector . publicApi . __modules__ [ moduleName ] [ propertyName ] ( ) , errorMessage ) ;
204
204
} ) ;
205
- } ) ;
205
+ } ) ;
206
206
207
207
describe ( "cache" , ( ) => {
208
208
it ( "executes implementation of method only once and returns the same result each time whent it is called (number return type)" , ( ) => {
@@ -433,12 +433,12 @@ describe("decorators", () => {
433
433
} ) ;
434
434
435
435
_ . each ( expectedResults , ( expectedResult : any ) => {
436
- it ( "returns proper result" , ( ) => {
436
+ it ( "returns proper result" , ( ) => {
437
437
const actualResult = testInstance . testMethod ( expectedResult ) ;
438
438
assert . deepEqual ( actualResult , expectedResult ) ;
439
439
} ) ;
440
440
441
- it ( "returns proper result when async" , ( ) => {
441
+ it ( "returns proper result when async" , ( ) => {
442
442
const promise = testInstance . testAsyncMehtod ( expectedResult ) ;
443
443
444
444
assert . notDeepEqual ( promise . then , undefined ) ;
@@ -449,20 +449,20 @@ describe("decorators", () => {
449
449
} ) ;
450
450
} ) ;
451
451
452
- it ( "method has same toString" , ( ) => {
452
+ it ( "method has same toString" , ( ) => {
453
453
assert . equal ( testInstance . testMethod . toString ( ) , undecoratedTestInstance . testMethod . toString ( ) ) ;
454
454
} ) ;
455
455
456
- it ( "method has same name" , ( ) => {
456
+ it ( "method has same name" , ( ) => {
457
457
assert . equal ( testInstance . testMethod . name , undecoratedTestInstance . testMethod . name ) ;
458
458
} ) ;
459
459
460
- it ( "does not eat errors" , ( ) => {
460
+ it ( "does not eat errors" , ( ) => {
461
461
assert . throws ( testInstance . throwMethod , testErrorMessage ) ;
462
462
assert . isRejected ( testInstance . rejectMethod ( ) , testErrorMessage ) ;
463
463
} ) ;
464
464
465
- it ( "calls performance service on method call" , async ( ) => {
465
+ it ( "calls performance service on method call" , async ( ) => {
466
466
const performanceService = testInjector . resolve ( "performanceService" ) ;
467
467
const processExecutionDataStub : sinon . SinonStub = sinon . stub ( performanceService , "processExecutionData" ) ;
468
468
@@ -486,4 +486,128 @@ describe("decorators", () => {
486
486
checkSubCall ( processExecutionDataStub . secondCall , "TestClass__testAsyncMehtod" ) ;
487
487
} ) ;
488
488
} ) ;
489
+
490
+ describe ( "deprecated" , ( ) => {
491
+ const testDepMessage = "Just stop using this!" ;
492
+ const warnings : string [ ] = [ ] ;
493
+ let testInjector : IInjector ;
494
+ interface ITestInterface {
495
+ testField : string ;
496
+ testProp : string ;
497
+ depMethodWithParam ( arg : any ) : any ;
498
+ depMethodWithoutParam ( ) : void ;
499
+ depAsyncMethod ( arg : any ) : Promise < any > ;
500
+ nonDepMethod ( ) : any ;
501
+ }
502
+ let testInstance : ITestInterface ;
503
+
504
+ function createTestInjector ( ) : IInjector {
505
+ testInjector = new Yok ( ) ;
506
+ testInjector . register ( "config" , { } ) ;
507
+ testInjector . register ( "options" , { } ) ;
508
+ testInjector . register ( "logger" , {
509
+ warn : ( message : string ) => {
510
+ warnings . push ( message ) ;
511
+ }
512
+ } ) ;
513
+
514
+ return testInjector ;
515
+ }
516
+
517
+ beforeEach ( ( ) => {
518
+ warnings . splice ( 0 , warnings . length ) ;
519
+ testInjector = createTestInjector ( ) ;
520
+
521
+ class TestClass implements ITestInterface {
522
+ public testField : string = "test" ;
523
+
524
+ @decoratorsLib . deprecated ( testDepMessage , testInjector )
525
+ public get testProp ( ) : string {
526
+ return "hi" ;
527
+ }
528
+
529
+ public set testProp ( value : string ) {
530
+ return ;
531
+ }
532
+
533
+ @decoratorsLib . deprecated ( testDepMessage , testInjector )
534
+ depMethodWithParam ( arg : any ) {
535
+ return arg ;
536
+ }
537
+
538
+ @decoratorsLib . deprecated ( testDepMessage , testInjector )
539
+ depMethodWithoutParam ( ) {
540
+ return ;
541
+ }
542
+
543
+ @decoratorsLib . deprecated ( testDepMessage , testInjector )
544
+ async depAsyncMethod ( arg : any ) {
545
+ return Promise . resolve ( arg ) ;
546
+ }
547
+
548
+ nonDepMethod ( ) {
549
+ return ;
550
+ }
551
+ }
552
+
553
+ testInstance = new TestClass ( ) ;
554
+ } ) ;
555
+
556
+ it ( "method without params" , ( ) => {
557
+ testInstance . depMethodWithoutParam ( ) ;
558
+ assert . equal ( warnings . length , 1 ) ;
559
+ assert . equal ( warnings [ 0 ] , `depMethodWithoutParam is deprecated. ${ testDepMessage } ` ) ;
560
+ } ) ;
561
+
562
+ it ( "method with params" , ( ) => {
563
+ const param = 5 ;
564
+ const result = testInstance . depMethodWithParam ( param ) ;
565
+ assert . equal ( result , param ) ;
566
+ assert . equal ( warnings . length , 1 ) ;
567
+ assert . equal ( warnings [ 0 ] , `depMethodWithParam is deprecated. ${ testDepMessage } ` ) ;
568
+ } ) ;
569
+
570
+ it ( "async method with params" , async ( ) => {
571
+ const param = 5 ;
572
+ const result = await testInstance . depAsyncMethod ( param ) ;
573
+ assert . equal ( result , param ) ;
574
+ assert . equal ( warnings . length , 1 ) ;
575
+ assert . equal ( warnings [ 0 ] , `depAsyncMethod is deprecated. ${ testDepMessage } ` ) ;
576
+ } ) ;
577
+
578
+ it ( "property getter" , async ( ) => {
579
+ const result = testInstance . testProp ;
580
+ assert . equal ( result , "hi" ) ;
581
+ assert . equal ( warnings . length , 1 ) ;
582
+ assert . equal ( warnings [ 0 ] , `testProp is deprecated. ${ testDepMessage } ` ) ;
583
+ } ) ;
584
+
585
+ it ( "property setter" , async ( ) => {
586
+ testInstance . testProp = "newValue" ;
587
+ assert . equal ( warnings . length , 1 ) ;
588
+ assert . equal ( warnings [ 0 ] , `testProp is deprecated. ${ testDepMessage } ` ) ;
589
+ } ) ;
590
+
591
+ it ( "non deprecated field" , async ( ) => {
592
+ const result = testInstance . testField ;
593
+ assert . equal ( result , "test" ) ;
594
+ assert . equal ( warnings . length , 0 ) ;
595
+ } ) ;
596
+
597
+ it ( "non deprecated method" , ( ) => {
598
+ testInstance . nonDepMethod ( ) ;
599
+ assert . equal ( warnings . length , 0 ) ;
600
+ } ) ;
601
+
602
+ it ( "class" , async ( ) => {
603
+ @decoratorsLib . deprecated ( testDepMessage , testInjector )
604
+ class TestClassDeprecated {
605
+ }
606
+
607
+ const depClass = new TestClassDeprecated ( ) ;
608
+ assert . isNotNull ( depClass ) ;
609
+ assert . equal ( warnings . length , 1 ) ;
610
+ assert . equal ( warnings [ 0 ] , `TestClassDeprecated is deprecated. ${ testDepMessage } ` ) ;
611
+ } ) ;
612
+ } ) ;
489
613
} ) ;
0 commit comments