-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Cannot use 'should' assertion style with mocha / chai / chai-as-promised #633
Comments
I've encountered the same. |
Mocha support is slightly limited - I'd suggest sticking with If someone has time to look into how |
@juliemr I came across the same issue as well. Looking at the code, https://github.com/chaijs/chai/blob/master/lib/chai/interface/should.js#L35
This isn't an answer, but hopefully it will give someone direction. |
Thanks @gabejohnson that got me on the right track. This works:
I think a check in Protractor to see if Object has been extended with should would be nice - then Protractor can add that tidibit to extend Promise. |
It breaks the same way in cucumber framework as well using protractor |
Btw, I try codes from @juliemr and it works. |
I'd suggest Object.defineProperty(
protractor.promise.Promise.prototype,
'should',
Object.getOwnPropertyDescriptor(Object.prototype, 'should')
); |
@domenic 👍 works like a charm and it's a bit cleaner than the first version posted here |
@domenic I get the following error when i'm trying to use the code. Can you plz help ? : ) TypeError: Property description must be an object: undefined |
@vladei I received a similar error until I confirmed the following as the correct order:
|
Note that as of protractor 4.0.0, the workaround above no longer seems to be required (partly due to #3214). Protractor no longer exposes a Promise object of it's own, and instead defers (no pun intended) to the (Note: if you need to work directly with Promises in protractor 4.0.0, such as var promise = require('selenium-webdriver').promise;
promise.all([promise1, promise2, promise3]) It would seem that the WebDriver promise inherits from // protractor.conf.js
onPrepare() {
// Load chai assertions
const chai = require("chai");
// Load chai-as-promised support
chai.use(require("chai-as-promised"));
// Initialise should API (attaches as a property on Object)
chai.should();
} |
Sweet, closing as fixed. |
I tried to use
myElement.getText().should.eventually.equal("foo")
as in the chai-as-promised manual, but gotTypeError: Cannot read property 'eventually' of undefined
. This is not a problem withchai-as-promised
either, becausemyElement.getText().should.equal("foo")
failed with a similar error. Usingexpect
works as expected, though.The text was updated successfully, but these errors were encountered: