当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mocha-each.default函数代码示例

本文整理汇总了TypeScript中mocha-each.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

 describe("convertTimeUnit", () => {
     forEach([
         ["ms", "MILLISECONDS"],
         ["s", "SECONDS"],
         ["m", "MINUTES"],
         ["h", "HOURS"],
         ["d", "DAYS"],
         ["w", "WEEKS"],
         ["M", "MONTHS"],
         ["y", "YEARS"]
     ]).it("should convert short format time unit: %s into %s", (timeUnit, expected) => {
         TimeUnitUtils.convertTimeUnit(timeUnit).should.be.equal(expected);
     });
     forEach([
         ["millisecond", "MILLISECONDS"],
         ["second", "SECONDS"],
         ["minute", "MINUTES"],
         ["hour", "HOURS"],
         ["day", "DAYS"],
         ["week", "WEEKS"],
         ["month", "MONTHS"],
         ["year", "YEARS"]
     ]).it("should convert long format time unit: %s into %s", (timeUnit, expected) => {
         TimeUnitUtils.convertTimeUnit(timeUnit).should.be.equal(expected);
     });
 });
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:26,代码来源:time_unit_utils.test.ts

示例2: TargetValidator

describe("TargetValidator", () => {
    const targetValidator: TargetValidator = new TargetValidator();

    const newNamedKairosDBTarget = (metricName) => {
        const target = new KairosDBTarget();
        target.metricName = metricName;
        return target;
    };
    const validTargets = [
        "named target",
        "another valid target",
        "yet another valid target"
    ].map(newNamedKairosDBTarget);
    const anInvalidTarget = new KairosDBTarget();
    const invalidTargets = [
        anInvalidTarget,
        null,
        newNamedKairosDBTarget(null)
    ];

    forEach(invalidTargets).it("should recognize target `%j` as invalid", (target) => {
        // when
        const targetIsValid = targetValidator.isValidTarget(target);
        // then
        // tslint:disable-next-line
        targetIsValid.should.be.false;
    });

    forEach(validTargets).it("should recognize target `%(metricName)s` as valid", (target) => {
        // when
        const targetIsValid = targetValidator.isValidTarget(target);
        // then
        // tslint:disable-next-line
        targetIsValid.should.be.true;
    });

    it("should recognize list of valid targets as valid", () => {
        // then
        const targets = validTargets.map((target) => {
            return {query: target};
        });
        // when
        const targetsAreValid = targetValidator.areValidTargets(targets);
        // then
        // tslint:disable-next-line
        targetsAreValid.should.be.true;
    });

    it("should recognize list of targets with an invalid target as invalid", () => {
        // given
        const targets = validTargets.concat([anInvalidTarget]).map((target) => {
            return {query: target};
        });
        // when
        const targetsAreValid = targetValidator.areValidTargets(targets);
        // then
        // tslint:disable-next-line
        targetsAreValid.should.be.false;
    });
});
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:60,代码来源:target_validator.test.ts

示例3: TemplatingUtils

describe("GroupBysBuilder", () => {
    const variables = {
        tagname1: ["v1", "v2", "v3"],
        tagname2: ["v4", "v5"]
    };
    const templatingSrvMock = buildTemplatingSrvMock(variables);
    const templatingUtils: TemplatingUtils =
        new TemplatingUtils(templatingSrvMock, {});
    const alwaysNotApplicableSamplingConverter = buildSamplingConverterMock(null, null, false);
    const groupBysBuilder: GroupBysBuilder = new GroupBysBuilder(templatingUtils, alwaysNotApplicableSamplingConverter);

    const testCases = [
        {
            groupBysDefinition: {
                tags: ["singletag"],
                time: [],
                value: [],
            },
            expectedGroupBys: [
                {
                    name: "tag",
                    tags: ["singletag"]
                }
            ]
        },
        {
            groupBysDefinition: {
                tags: ["singletag1", "singletag2", "singletag3"],
                time: [],
                value: [],
            },
            expectedGroupBys: [
                {
                    name: "tag",
                    tags: ["singletag1", "singletag2", "singletag3"]
                }
            ]
        },
        {
            groupBysDefinition: {
                tags: ["$tagname1"],
                time: [],
                value: [],
            },
            expectedGroupBys: [
                {
                    name: "tag",
                    tags: variables.tagname1
                }
            ]
        },
        {
            groupBysDefinition: {
                tags: ["$tagname1", "$tagname2"],
                time: [],
                value: [],
            },
            expectedGroupBys: [
                {
                    name: "tag",
                    tags: _.concat(variables.tagname1, variables.tagname2)
                }
            ]
        },
        {
            groupBysDefinition: {
                tags: ["$tagname1", "$tagname2", "singletag1", "singletag2"],
                time: [],
                value: [],
            },
            expectedGroupBys: [
                {
                    name: "tag",
                    tags: _.concat(variables.tagname1, variables.tagname2, "singletag1", "singletag2")
                }
            ]
        },
        {
            groupBysDefinition: {
                tags: [],
                time: [new GroupByTimeEntry("5", "HOURS", 1)],
                value: [],
            },
            expectedGroupBys: [
                {
                    name: "time",
                    group_count: 1,
                    range_size: {
                        value: "5",
                        unit: "HOURS"
                    }
                }
            ]
        },
        {
            groupBysDefinition: {
                tags: [],
                time: [new GroupByTimeEntry("5", "HOURS", 1), new GroupByTimeEntry("1", "MINUTE", 2)],
                value: [],
            },
//.........这里部分代码省略.........
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:101,代码来源:group_bys_builder.test.ts

示例4: SeriesNameBuilder

describe("SeriesNameBuilder", () => {
    const seriesNameBuilder: SeriesNameBuilder = new SeriesNameBuilder();
    const testParameters = [
        ["metricName", [
            {
                group: {
                    key: "GROUPby1",
                    key2: "GROUPby2"
                },
                name: "tag"
            }]
        ],
        ["metricName", [
            {
                group: {
                    group_number: 1225345
                },
                name: "value"
            }]
        ],
        ["metricName", [
            {
                group: {
                    group_number: 456
                },
                group_count: 3034,
                name: "time"
            }]
        ],
        ["metricName", [
            {
                group: {
                    group_number: 123
                },
                name: "value"
            },
            {
                group: {
                    group_number: 456
                },
                group_count: 3,
                name: "time"
            }]
        ],
        ["onlyMetricName", [
            {
                group: {
                    key: "GROUPby1",
                    key2: "GROUPby2"
                },
                name: "tag"
            },
            {
                group: {
                    group_number: 123
                },
                name: "value"
            },
            {
                group: {
                    group_number: 456
                },
                group_count: 3,
                name: "time"
            }]
        ],
        ["metricName", [
            {
                group: {
                    key: "GROUPby1",
                    key2: "GROUPby2"
                },
                name: "tag"
            },
            {
                group: {
                    group_number: 123
                },
                name: "value"
            },
            {
                group: {
                    group_number: 456
                },
                group_count: 3,
                name: "time"
            }]
        ]
    ];

    forEach(testParameters).it("should build expected series name from %j",
        (metricName, groupBys) => {
            // when
            const seriesName = seriesNameBuilder.build(metricName, null, groupBys);
            // then
            seriesName.should.contain(metricName);
            groupBys.forEach((groupBy) => {
                switch (groupBy.name) {
                    case "tag":
                        _.values(groupBy.group).forEach((value) => {
//.........这里部分代码省略.........
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:101,代码来源:series_name_builder.test.ts

示例5: TemplatingFunctionsCtrl

describe("TemplatingFunctionsController", () => {
    const variables = {
        variable1: ["a", "b", "c"],
        variable2: ["d", "e", "f"]
    };
    const templatingSrvMock = buildTemplatingSrvMock(variables);
    const templatingFunctionsController: TemplatingFunctionsCtrl =
        new TemplatingFunctionsCtrl(new TemplatingFunctionResolver(new TemplatingUtils(templatingSrvMock, {})));
    const metricsFunction = new TemplatingFunction("metrics", (metricNamePart) => ["metric1", "metric2", "metric3"]);
    const tagNamesFunction = new TemplatingFunction("tag_names", (metricName) => ["tag1", "tag2", "tag3"]);
    const tagValuesFunction = new TemplatingFunction("tag_values",
        (metricName, tagName, filters) => ["tag_value1", "tag_value2", "tag_value3"]);
    [metricsFunction, tagNamesFunction, tagValuesFunction].forEach((func) => {
        templatingFunctionsController.register(func);
        func.body = sinon.spy(func.body);
    });

    forEach([
        ["metrics(param)", metricsFunction],
        ["metrics(param1,param2)", metricsFunction],
        ["metrics(param1, param2)", metricsFunction],
        ["tag_names(metric)", tagNamesFunction],
        ["tag_values(metric,param2,param3)", tagValuesFunction],
        ["tag_values(metric, param2, param3)", tagValuesFunction],
        ["tag_values(metric, param2, param3, filter1=$filter_variable1, filter2=$filter_variable2)", tagValuesFunction],
    ]).it("should resolve %s as a function", (functionQuery, expectedFunction) => {
        // when
        templatingFunctionsController.resolve(functionQuery)();
        // then
        assert(expectedFunction.body.calledOnce);
        expectedFunction.body.reset();
    });

    forEach([
        "nonExistingfunction(1,321)",
        "metrics()",
        "tag_names()",
        "tag_values()",
    ]).it("should not resolve %s as a function", (functionQuery) => {
        expect(() => {
            // when
            templatingFunctionsController.resolve(functionQuery);
        }).to.throw();
    });

    it("should convert single filter argument to single entry filter object", () => {
        // given
        const functionQuery = "tag_values(metric_name,tag_name,filter1=$variable1)";
        const expectedFunction = tagValuesFunction;
        // when
        templatingFunctionsController.resolve(functionQuery)();
        // then
        assert(expectedFunction.body.calledWith("metric_name", "tag_name", {filter1: variables.variable1}));
        expectedFunction.body.reset();
    });

    it("should convert single filter argument with prefix and suffix to single entry filter object", () => {
        // given
        const functionQuery = "tag_values(metric_name,tag_name,filter1=prefix_$variable1_suffix)";
        const expectedFunction = tagValuesFunction;
        const expectedFilters = _.map(variables.variable1, (value) => "prefix_" + value + "_suffix");
        // when
        templatingFunctionsController.resolve(functionQuery)();
        // then
        assert(expectedFunction.body.calledWith("metric_name", "tag_name", {filter1: expectedFilters}));
        expectedFunction.body.reset();
    });

    it("should convert multiple filter arguments to multiple entries filter object", () => {
        // given
        const functionQuery = "tag_values(metric_name,tag_name, filter1=$variable1, filter2=$variable2)";
        const expectedFunction = tagValuesFunction;
        // when
        templatingFunctionsController.resolve(functionQuery)();
        // then
        assert(expectedFunction.body.calledWith("metric_name", "tag_name", {filter1: variables.variable1, filter2: variables.variable2}));
        expectedFunction.body.reset();
    });
});
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:79,代码来源:templating_functions_ctrl.test.ts


注:本文中的mocha-each.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。