regimen
Define what can be consumed. A Chai plugin for design systems at The Grid.
Last updated 5 years ago by paulyoung .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install regimen 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.2.2                                ...           latest (5 years ago)

12 Versions

  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.9                                ...           5 years ago
  • 0.1.7                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |