【问题标题】:how to get the result of a test in the afterEach in Jasmine如何在 Jasmine 的 afterEach 中获取测试结果
【发布时间】: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


    【解决方案1】:

    实际上我刚刚发现我的解决方案正在运行,currentSpec.failedExpectations 在测试通过时返回 [] 但是当测试失败时,我实际上得到了一个带有失败消息和所有内容的大 json 响应。

    我会将问题/答案保留在这里,可能对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 2013-06-23
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多