javascriptmocha.jsshould.js

How to use OR condition with should() in mocha


I want to use two values to get compared so that if either is true then my test should pass.Using the below code is comapring only 1st condition and failing the test.

if (typeof lng !== 'undefined') {
data.lng.should.equal(lng) || data.cityLng.should.equal(lng);

}

How should I do this?


Solution

  • Try this:

    if (typeof lng !== 'undefined') {
        lng.should.be.equalOneOf(data.lng, data.cityLng);
    

    See documentation.