【发布时间】:2012-09-26 09:38:30
【问题描述】:
有没有办法获取当前正在运行的测试的名称?
一些(高度简化的)代码可能有助于解释。我想避免在对performTest 的调用中重复"test1" / "test2":
describe("some bogus tests", function () {
function performTest(uniqueName, speed) {
var result = functionUnderTest(uniqueName, speed);
expect(result).toBeTruthy();
}
it("test1", function () {
performTest("test1", "fast");
});
it("test2", function () {
performTest("test2", "slow");
});
});
更新 我看到我需要的信息在:
jasmine.currentEnv_.currentSpec.description
或者可能更好:
jasmine.getEnv().currentSpec.description
【问题讨论】:
-
仅供参考,
expect(result).toBeTruthy不会测试任何东西,expect(result).toBeTruthy()会进行测试。 -
查看此答案以添加 Jasmine 自定义报告器:stackoverflow.com/a/48664485/293280
标签: javascript unit-testing jasmine