只有在Jasmine测试失败的情况下才可以做某事吗?并列与afterEach()
之后执行it()
无论结果如何,我正在寻找一些方法来执行代码只有在it()
一个失败的期望之后.
这个问题不是Angular特有的,但在我的场景中,我正在测试一个Angular服务,它使用输出调试消息$log
.我不想让我的控制台混乱以获得成功的测试,但只显示失败测试的附加信息.
describe("MyService", function() {
var MyService, $log;
beforeEach(function() {
inject(function (_MyService_, _$log_) {
MyService = _MyService_;
$log = _$log_;
});
});
afterEach(function () {
if (/* test failed */) {
//console.log($log.debug.logs);
}
});
it("should output debug logs when this fails", function() {
//do something with MyService that would put a message in $log
expect(false).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
我正在运行Jasmine 2.2.0.
编辑:这是一个非常简单的小提琴,显示Jasmine 1.3 jasmine.getEnv().currentSpec
解决方案不再有效.
这里是一个黑客重新启用jasmine.getEnv().currentSpec
在茉莉花2(排序的,result
是不完整的spec
对象,但包含id
,description
,fullName
,failedExpectations
,和passedExpectations
):
jasmine.getEnv().addReporter({
specStarted(result) {
jasmine.getEnv().currentSpec = result;
},
specDone() {
jasmine.getEnv().currentSpec = null;
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4037 次 |
最近记录: |