0.2.2 • Published 10 years ago
regimen v0.2.2
Regimen 
Define what can be consumed.
A Chai plugin for design systems at The Grid.
Usage
chai = require "chai"
regimen = require "regimen"
chai.use regimenBlocks
Properties
The following assertions are equivalent, however the latter provides a better error message:
expect(block.cover).to.exist
# AssertionError: expected undefined to existexpect(block).with.a "cover"
# AssertionError: expected block 123 to have a coverAgain, assertions could be written as follows:
expect(block.cover.orientation).to.equal "portrait"
# AssertionError: expected 'landscape' to equal 'portrait'expect(block).to.have.a("cover.orientation").equal "portrait"
# AssertionError: expected block 123 to have a cover.orientation equal to 'portrait' but got 'landscape'expect(block).to.have.a("cover").oriented "portrait"
# AssertionError: expected block 123 to have a cover with 'portrait' orientation but got 'landscape'However, if the cover were missing the latter provides the most accurate error message:
expect(block.cover.orientation).to.equal "portrait"
# TypeError: Cannot read property 'orientation' of undefinedexpect(block).to.have.a("cover.orientation").equal "portrait"
# AssertionError: expected block 123 to have a cover.orientationexpect(block).to.have.a("cover").oriented "portrait"
# AssertionError: expected block 123 to have a coverThe second option should only serve as interim support for future additions in the block structure until custom properties and methods can be added.
Optionals
To specify requirements about optional content, use maybe:
expect(block).to.maybe.have.a("title")?.with.length.lte 20Types and Subtypes
expect(block1).to.be.ofType "video"
expect(block2).to.not.be.ofType "video" expect(block1).to.be.subtypeOf "media"
expect(block2).to.not.be.subtypeOf "media"Items
Reposts
expect(item1).to.be.a.repost
expect(item2).to.not.be.a.repostDevelopment
npm install
npm test