0

It would be helpful to be able to do as chaijs says in their doc: return doSomethingAsync().should.eventually.equal("foo");

This would speed up writing my e2e tests as I wouldn't have to explicitly resolve the promises like this:

// I wouldn't have to resolve this promise like this as it's very verbose and slows down
// my development 
return somePromise.then(function(resolvedPromise){
  expect(resolvedPromise).to.equal(expectedResult); 
});

It would be nice to use chai; chai.expect; chai.should(); chai-as-promise to resolve those promises and assert on them very quickly; however, nothing I have tried worked so far; a search on SO seems to suggest that Chai uses different promise types than Protractor does and that incompatibility in promise type might be resulting in

TypeError: Cannot read property 'should' of undefined"

This is how I import these libs:

var chaiAsPromised = require('chai-as-promised');
  chai.use(chaiAsPromised);
  var expect = chai.expect;
  var should = require('chai').should();
  var assert = chai.assert;

Has anyone been successful at using return doSomethingAsync().should.eventually.equal("foo"); without using other libraies like 'Q'? Again I don't want to rely on other libs like 'Q'; I just want to use pure chaijs in my protractor e2e if it's possible; NOT the expect() but the .should.eventually.....

Thanks

pelican
  • 5,846
  • 9
  • 43
  • 67
  • Why don't you resolve the promise with expect ? `expect(somePromise).to.equal(expectedResult);` – Florent B. May 25 '16 at 13:50
  • Because I have to manually resolve the promise. Basically, I have to put that expect().to.equal() into the callback of the promise, which adds extra code to the tests. With the .should.eventually..... syntax, I wouldn't have to and my tests would be less verbose – pelican May 25 '16 at 13:55

0 Answers0