First Class Expectations
A chai plugin to separate expectations from the the values they are tested on.
var expect = expect;var should = ; var expectation = should;expectation;to;
This example shows the correspondence beetween the expect
syntax and
should
builder syntax. This extends to all of chai’s language
properties—so in general the following are equivalent.
shouldabc;abc shouldab;ab
Expecation also have a label
property that describes the expectation
shouldbedefinedandlabel// -> 'should be defined and equal 4'
Use Cases
Building custom expecations.
var shouldHaveAddress = shouldhave as andwithvar shouldHaveExtendedAddress = shouldHaveAddresswithand shouldHaveAddressshouldHaveExtendedAddress
Running labeled tests.
{ expectations
The plugin integrates nicely with mocha-when-then.
shouldHaveAddress = shouldhaveproperty'address'shouldHaveAddress.label = 'should have address' Given 'person'address: name: 'Willy'Then 'person'shouldHaveAddresswithkey'name' When -> @personaddress.street = 'Chocolate Lane'And -> @personaddress.city = 'Tiny Town'Then 'person'shouldHaveAdresswithkey'street'And 'person'shouldHaveAdresswithkey'city'
This creates the following test lables
person should have address with key name
person should have address with key street
person should have address with key city