2015-09-04 7 views

उत्तर

8

Chai expect/should documentation देखकर, इस परीक्षण को करने के कई तरीके हैं।

ध्यान दें कि आप "और" का उपयोग करके श्रृंखला बना सकते हैं लेकिन स्पष्ट रूप से नहीं "या" - इच्छा है कि उनके पास यह कार्यक्षमता हो।

  1. चेक एक वस्तु एक सच परीक्षण में सफ़ल या नहीं:

.satisfy (विधि)

@param{ Function }matcher 
@param{ String }message_optional_ 

Asserts that the target passes a given truth test. 

उदाहरण:

expect(1).to.satisfy(function(num) { return num > 0; }); 

आपके मामले में, परीक्षण करने के लिए एक "या" हालत:

yourVariable.should.satisfy(function (num) { 
    if ((num === 4) || (num === 5)) { 
     return true; 
    } else { 
     return false; 
    } 
}); 
  1. चेक कि क्या एक नंबर एक सीमा के भीतर है:

.within (शुरू, खत्म)

@param{ Number }startlowerbound inclusive 
@param{ Number }finishupperbound inclusive 
@param{ String }message_optional_ 

Asserts that the target is within a range. 

उदाहरण:

expect(7).to.be.within(5,10); 
+2

जो काम करेगा - हम कुछ भी कर सकते हैं जैसे '(num == = 4 || संख्या === 5) .should.be.true – MonkeyBonkey

संबंधित मुद्दे