Prashanth Sams Prashanth Sams - 2 months ago 28
Javascript Question

Failed: Cannot read property 'results' of undefined

Snippet for taking screenshot on Test Failure

afterEach(function() {

var spec = jasmine.getEnv().currentSpec;
var passed = spec.results().passed();

if (!passed) {
browser.takeScreenshot().then(function(png) {
writeScreenShot(png, "screenshot.png");
});
}

function writeScreenShot(data, filename) {
var stream = fs.createWriteStream(filename);
stream.write(new Buffer(data, 'base64'));
stream.end();
}

});


Console error

Message:
Failed: Cannot read property 'results' of undefined
Stack:
TypeError: Cannot read property 'results' of undefined
at Object.<anonymous>





it returns
undefined
here,

var spec = jasmine.getEnv().currentSpec;
console.log(spec);


Looks like issues due to
Jasmine 2
; any alternate solutions also welcome! I use Jasmine 2

Answer

As of Jasmine 2.0, env.currentSpec is no longer supported.

https://github.com/jasmine/jasmine/issues/1212