regimen
v0.2.2
Published
Define what can be consumed. A Chai plugin for design systems at The Grid.
Downloads
5
Readme
Regimen
Define what can be consumed.
A Chai plugin for design systems at The Grid.
Usage
chai = require "chai"
regimen = require "regimen"
chai.use regimen
Blocks
Properties
The following assertions are equivalent, however the latter provides a better error message:
expect(block.cover).to.exist
# AssertionError: expected undefined to exist
expect(block).with.a "cover"
# AssertionError: expected block 123 to have a cover
Again, 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 undefined
expect(block).to.have.a("cover.orientation").equal "portrait"
# AssertionError: expected block 123 to have a cover.orientation
expect(block).to.have.a("cover").oriented "portrait"
# AssertionError: expected block 123 to have a cover
The 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 20
Types 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.repost
Development
npm install
npm test