all files / core/decorators/ async-test-decorator.ts

100% Statements 15/15
100% Branches 4/4
100% Functions 4/4
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31   26×     110×     110× 18×         919× 50×           987× 110× 110×     110×      
import "reflect-metadata";
 
export function AsyncTest(description?: string) {
   return  (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any/*Promise<void>*/>) => {
 
      // check if this has been registered as a test already
      let tests: Array<any> = Reflect.getMetadata("alsatian:tests", target);
 
      // if there are no tests registered yet then register it
      if (!tests) {
         tests = [ {
            key: propertyKey
         } ];
      }
      // otherwise add it to the register if it's not already there
      else if (tests.filter(test => test.key === propertyKey).length === 0) {
         tests.push( {
            key: propertyKey
         } );
      }
 
      // mark it as async and add the description
      let test = tests.filter(test => test.key === propertyKey)[0];
      test.isAsync = true;
      test.description = description;
 
      // update the register
      Reflect.defineMetadata("alsatian:tests", tests, target);
   };
}