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

100% Statements 12/12
100% Branches 4/4
100% Functions 3/3
100% Lines 10/10
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   82×     166×     166× 32×       32×     1088× 92×       92×        
import "reflect-metadata";
 
export function Test(description?: string) {
  return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
 
    // 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,
         description: description
      } ];
      Reflect.defineMetadata("alsatian:tests", tests, target);
    }
    // otherwise add it to the register
    else if (tests.filter(test => test.key === propertyKey).length === 0) {
      tests.push( {
         key: propertyKey,
         description: description
      });
      Reflect.defineMetadata("alsatian:tests", tests, target);
    }
};
}