【发布时间】:2019-11-20 22:44:46
【问题描述】:
我正在编写一个全局 afterEach 到 console.log 仅在测试失败时进行一些日志记录。
jasmine.getEnv().topSuite().afterEach({
fn: function () {
if(\*test failed */){
console.log('print some logs');
}
}
});
我搜索了一下,我找到了这个答案
https://stackoverflow.com/a/39882823/4324176
但是根据这里的 Jasmine 文档,这个是不正确的 https://jasmine.github.io/2.1/custom_reporter.html
specDone 在 it 及其关联的 beforeEach 和 afterEach 函数已运行。
所以基本上我在 protractor.conf.js onPrepare() 中的代码是
jasmine.getEnv().addReporter({
specStarted(result) {
jasmine.getEnv().currentSpec = result;
},
specDone() {
jasmine.getEnv().currentSpec = null;
}
});
jasmine.getEnv().topSuite().afterEach({
fn: function () {
const currentSpec = jasmine.getEnv().currentSpec;
if(currentSpec.failedExpectations.length){
console.log('print some logs');
}
}
});
但问题是 currentSpec.failedExpectations 总是 [] 因为结果尚未更新。
【问题讨论】:
标签: logging jasmine protractor