regimen

0.2.2 • Public • Published

Regimen Build Status

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."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

Readme

Keywords

Package Sidebar

Install

npm i regimen

Weekly Downloads

10

Version

0.2.2

License

MIT

Last publish

Collaborators

  • paulyoung