Regimen
Define what can be consumed.
A Chai plugin for design systems at The Grid.
Usage
chai = require "chai"regimen = require "regimen"chaiuse regimen
Blocks
Properties
The following assertions are equivalent, however the latter provides a better error message:
expectblockcovertoexist# AssertionError: expected undefined to exist
expectblockwitha "cover"# AssertionError: expected block 123 to have a cover
Again, assertions could be written as follows:
expectblockcoverorientationtoequal "portrait"# AssertionError: expected 'landscape' to equal 'portrait'
expectblocktohavea"cover.orientation"equal "portrait"# AssertionError: expected block 123 to have a cover.orientation equal to 'portrait' but got 'landscape'
expectblocktohavea"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:
expectblockcoverorientationtoequal "portrait"# TypeError: Cannot read property 'orientation' of undefined
expectblocktohavea"cover.orientation"equal "portrait"# AssertionError: expected block 123 to have a cover.orientation
expectblocktohavea"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
:
expectblocktomaybehavea"title"?withlengthlte 20
Types and Subtypes
expectblock1tobeofType "video" expectblock2tonotbeofType "video"
expectblock1tobesubtypeOf "media" expectblock2tonotbesubtypeOf "media"
Items
Reposts
expectitem1tobearepost expectitem2tonotbearepost
Development
npm installnpm test