all files / core/decorators/ test-case-decorator.js

100% Statements 21/21
100% Branches 6/6
100% Functions 3/3
100% Lines 20/20
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 32 33 34 35 36 37 38 39 40  709× 709× 1060×   709×   835×   835× 47×     47×   4479× 223×     223×     835×   835× 274×     835×       835×      
"use strict";
require("reflect-metadata");
var _metadata_keys_1 = require("./_metadata-keys");
function TestCase() {
    var testCaseArguments = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        testCaseArguments[_i - 0] = arguments[_i];
    }
    return function (target, propertyKey, descriptor) {
        // check if this has been registered as a test already
        var tests = Reflect.getMetadata(_metadata_keys_1.TESTS, target);
        // if there are no tests registered yet then register it
        if (!tests) {
            tests = [{
                    key: propertyKey
                }];
            Reflect.defineMetadata(_metadata_keys_1.TESTS, tests, target);
        }
        else if (tests.filter(function (test) { return test.key === propertyKey; }).length === 0) {
            tests.push({
                key: propertyKey
            });
            Reflect.defineMetadata(_metadata_keys_1.TESTS, tests, target);
        }
        // check if there are test cases already associated with this test
        var testCases = Reflect.getMetadata(_metadata_keys_1.TEST_CASES, target, propertyKey);
        // if not create an empty array
        if (!testCases) {
            testCases = [];
        }
        // add the test case to the list
        testCases.unshift({
            arguments: testCaseArguments
        });
        // update the list of test cases
        Reflect.defineMetadata(_metadata_keys_1.TEST_CASES, testCases, target, propertyKey);
    };
}
exports.TestCase = TestCase;
//# sourceMappingURL=test-case-decorator.js.map