What is the difference between chai and chai as promised in mocha framework while using protractor ?
Chai - Test Assertion Library which allows you to test your code with keywords such as expect
, should
etc. But while using Chai you have to take care of promises. For example
var expect = require('chai').expect;
it('should display correct tile', function() {
var blah = 'foo';
var title = browser.getTitle();
return title.then(function(actualTitle) {
expect(actualTitle).to.equal(expectedTitle);
});
});
On the other hand if you use chai as promised then you do not need to handle promises explicitly. That could be done with the help of Chai as promised
library. For example;
var chai = require('chai');
var expect = chai.expect;
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
it('should display correct title', function() {
var actualTitle = browser.getTitle();
return expect(actualTitle).to.eventually.equal(expectedTitle);
});
Chai is a BDD assertion library - providing you with common keywords such as assert
or should
etc.
Chai as Promised is an extension of that library specifically made to handle assertions with promises (as opposed to resolving them manually yourself).
https://github.com/domenic/chai-as-promised/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With