protractor testing with mocha and chai - promise not resolving

111 views
Skip to first unread message

Jens Hoffmann

unread,
Nov 11, 2015, 12:16:44 PM11/11/15
to AngularJS
Hi,

I have a protractor test in which I would like to check the count of select boxes. 
I am using chai as promised: (see also link here: https://angular.github.io/protractor/#/frameworks)

The problem is that I don't want to resolve the promise manually like below (see (2) ).

I am using mocha, chai by the way. 

Could you please help me?  


// Page Object
var ProductDetailPO = function () {
    // ...
};

ProductDetailPO.prototype = Object.create({}, {
    selectBoxesNumber: {
        get: function () {
            return element.all(by.css('.dropdownSelect')).count();
        }
    }
});

module.exports = ProductDetailPO;


// productDetail.spec.js
var po = new ProductDetailPO();
    
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;

// Doesn't work like that (1)
it('only one select should be enabled "',
  function () {
      expect(po.selectBoxesCount).to.be.above(5);
  });
  
// The following would work: (2)
po.selectBoxesCount.then(function (number) {
    expect(number).to.equal(5);
});

greetings 
jens 

Jens Hoffmann

unread,
Nov 12, 2015, 11:08:31 AM11/12/15
to AngularJS
I think I found the solution myself. 
If a promise is used the eventually keyword has to be used: 

// this code is working
expect(po.selectBoxes.count()).to.eventually.equal(4);

see link here: http://chaijs.com/plugins/chai-as-promised
Reply all
Reply to author
Forward
0 new messages