MochaTest

About

When you call MochaSuite.should() or MochaSuite.specify(), an instance of this class is returned that encapsulates the tests to be run. You never instantiate this class directly, and the only functions you will normally call are .expect(), .only() and .skip().

API

.expect()

.expect(value : any { ; message : Text }) : Object

Call this function to make an assertion. value is the value or expression to be tested, and message is a custom failure message.

This function returns a new instance of the .bdd assertion class passed to the MochaRunner constructor. The default assertion class is ChaiBdd, but can be changed by passing a different .bdd class.

See the ChaiBdd documentation for more information on how to build assertions after calling .expect().


.only()

.only() : cs.js.MochaTest

Sometimes it is useful to limit the number of tests that are run when you are working through multiple iterations of the same code. If .only() has been called on any tests within a suite, only those tests will be run. Note that more than one test can be marked with .only().

The current test is returned for chaining.

Example

Function testCapitalize($suite : cs.js.MochaSuite)
  var $it : cs.js.MochaSuite
  
  $it:=$suite.describe("capitalize()")

  // Only this test will be run, the second one will be skipped
  $it.should("capitalize only the first character by default"; \
    Formula(This.expect(_.capitalize("bAR")).to.strict.equal("BAR"))\
  ).only()

  $it.should("capitalize the first character and lowercase the rest if $lowercase is true"; \
    Formula(This.expect(_.capitalize("bAR"; True)).to.strict.equal("Bar"))\
  )

.skip()

.skip() : cs.js.MochaTest

Sometimes it is useful to temporarily exclude some tests that are failing when you are working through multiple iterations of the same code. If .skip() has been called on any tests within a suite, those tests will not be run. Note that more than one test can be marked with .skip().

The current test is returned for chaining.

Example

Function testCapitalize($suite : cs.js.MochaSuite)
  var $it : cs.js.MochaSuite
  
  $it:=$suite.describe("capitalize()").skip()
  
  // This test will not be run
  $it.should("capitalize only the first character by default"; \
    Formula(This.expect(_.capitalize("bAR")).to.strict.equal("BAR"))\
  ).skip()
    
  $it.should("capitalize the first character and lowercase the rest if $lowercase is true"; \
    Formula(This.expect(_.capitalize("bAR"; True)).to.strict.equal("Bar"))\
  )
Last Updated:
Contributors: Aparajita