AlwaysNoob
AlwaysNoob

Reputation: 11

What is the difference between Jasmine “Expect” and Chai “Expect”? Which one is preferred to use?

I'm new to the protractor, thanks in advance to whoever answers my questions:

  1. Is the protractor built based on jasmine?
  2. What is the difference between jasmine "Expect" and Chai "Expect"? Which one is preferred to use? Seems most people prefer the "chai" assertion, What is the advantage of "chai"?

Upvotes: 1

Views: 310

Answers (1)

yong
yong

Reputation: 13722

  1. Jasmine included in Protractor installation
  2. Jasmine support promise natively, but Chai
  3. Jasmine provided assertion apis less than Chai
  4. You can use chai-as-promise with Chai to support promise
  5. Chai can work with any test script by Test Framework, not limit on Jasmine
// Jasmine expect example
expect(some_ele.getText()).toEqual(some_text)

// Chai without using chai-as-promise
some_ele.getText().then(function(txt){
   expect(txt).to.be(some_text)
})

// Chai use chai-as-promise together
expect(some_ele.getText()).to.be(some_text)

// When use await/async for Jasmine expect
expect(await some_ele.getText()).toEqual(some_text)

// When use await/async for Chai expect and without chai-as-promise
expect(await some_ele.getText()).to.be(some_text)

Upvotes: 1

Related Questions