@@ -58,14 +58,14 @@ describe("decorators", () => {
5858 generatePublicApiFromExportedDecorator ( ) ;
5959 const actualResult : any = $injector . publicApi . __modules__ [ moduleName ] [ propertyName ] ( ) ;
6060 assert . deepEqual ( actualResult , expectedResult ) ;
61- } ) ;
61+ } ) ;
6262
6363 it ( `passes correct arguments to original function, when argument type is: ${ _ . isArray ( expectedResult ) ? "array" : typeof ( expectedResult ) } ` , ( ) => {
6464 $injector . register ( moduleName , { propertyName : ( arg : any ) => arg } ) ;
6565 generatePublicApiFromExportedDecorator ( ) ;
6666 const actualResult : any = $injector . publicApi . __modules__ [ moduleName ] [ propertyName ] ( expectedResult ) ;
6767 assert . deepEqual ( actualResult , expectedResult ) ;
68- } ) ;
68+ } ) ;
6969 } ) ;
7070
7171 it ( "returns Promise, which is resolved to correct value (function without arguments)" , ( done : mocha . Done ) => {
@@ -202,7 +202,7 @@ describe("decorators", () => {
202202 generatePublicApiFromExportedDecorator ( ) ;
203203 assert . throws ( ( ) => $injector . publicApi . __modules__ [ moduleName ] [ propertyName ] ( ) , errorMessage ) ;
204204 } ) ;
205- } ) ;
205+ } ) ;
206206
207207 describe ( "cache" , ( ) => {
208208 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", () => {
433433 } ) ;
434434
435435 _ . each ( expectedResults , ( expectedResult : any ) => {
436- it ( "returns proper result" , ( ) => {
436+ it ( "returns proper result" , ( ) => {
437437 const actualResult = testInstance . testMethod ( expectedResult ) ;
438438 assert . deepEqual ( actualResult , expectedResult ) ;
439439 } ) ;
440440
441- it ( "returns proper result when async" , ( ) => {
441+ it ( "returns proper result when async" , ( ) => {
442442 const promise = testInstance . testAsyncMehtod ( expectedResult ) ;
443443
444444 assert . notDeepEqual ( promise . then , undefined ) ;
@@ -449,20 +449,20 @@ describe("decorators", () => {
449449 } ) ;
450450 } ) ;
451451
452- it ( "method has same toString" , ( ) => {
452+ it ( "method has same toString" , ( ) => {
453453 assert . equal ( testInstance . testMethod . toString ( ) , undecoratedTestInstance . testMethod . toString ( ) ) ;
454454 } ) ;
455455
456- it ( "method has same name" , ( ) => {
456+ it ( "method has same name" , ( ) => {
457457 assert . equal ( testInstance . testMethod . name , undecoratedTestInstance . testMethod . name ) ;
458458 } ) ;
459459
460- it ( "does not eat errors" , ( ) => {
460+ it ( "does not eat errors" , ( ) => {
461461 assert . throws ( testInstance . throwMethod , testErrorMessage ) ;
462462 assert . isRejected ( testInstance . rejectMethod ( ) , testErrorMessage ) ;
463463 } ) ;
464464
465- it ( "calls performance service on method call" , async ( ) => {
465+ it ( "calls performance service on method call" , async ( ) => {
466466 const performanceService = testInjector . resolve ( "performanceService" ) ;
467467 const processExecutionDataStub : sinon . SinonStub = sinon . stub ( performanceService , "processExecutionData" ) ;
468468
@@ -486,4 +486,128 @@ describe("decorators", () => {
486486 checkSubCall ( processExecutionDataStub . secondCall , "TestClass__testAsyncMehtod" ) ;
487487 } ) ;
488488 } ) ;
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+ } ) ;
489613} ) ;
0 commit comments