Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between chai and chai as promised

What is the difference between chai and chai as promised in mocha framework while using protractor ?

like image 404
Emna Ayadi Avatar asked Dec 25 '22 06:12

Emna Ayadi


2 Answers

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);
});
like image 100
Priyanshu Shekhar Avatar answered Feb 01 '23 04:02

Priyanshu Shekhar


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/

like image 32
Gunderson Avatar answered Feb 01 '23 04:02

Gunderson