How to jasmine.getenv().currentspec with jasmine 2

2020-07-18 02:09发布

I want to get the passed or failed status of my test after each spec is executed:

var passed = jasmine.getEnv().currentSpec.results().passed();
      if (!passed) {
        browser.takeScreenshot().then(function(png) {
          writeScreenShot(png, filename, path);
        };
      }

but jasmine.getEnv().currentSpec is returning undefined, I am using Jasmine 2.3 how can I get the currentSpec with Jasmine 2.3

标签: jasmine
2条回答
Evening l夕情丶
2楼-- · 2020-07-18 02:54

It's likely that you are calling this from outside of the current spec. jasmine.getEnv().currentSpec will be null if there is no current spec, for example if it is called in afterAll or beforeAll blocks. Make sure that this code is invoked in the context of a spec.

I can't confirm that this is the problem without seeing more context, but this looks like it.

查看更多
淡お忘
3楼-- · 2020-07-18 02:54

Are you using Jasmine 2.0? env.currentSpec is no longer supported with Jasmine 2.0.

查看更多
登录 后发表回答