chai-by-proxy
v0.1.1
Published
Empowers chai's assertions using es6 proxy
Downloads
24
Maintainers
Readme
chai-by-proxy
Getting started
$ npm install --save-dev chai-by-proxy
node < 6
$ npm install --save-dev harmony-reflect
$ echo "--harmony_proxies" >> test/mocha.opts
$ echo "--require harmony-reflect" >> test/mocha.opts
node 0.10
$ echo "--harmony_collections" >> test/mocha.opts
Usage
var chai = require('chai')
chai.use(require('chai-by-proxy'))
have/has
(starts a chain)
obj = { foo: { bar: 'baz' } })
obj.should.have.foo.bar.eq('baz')
// same as
obj.should.have.property('foo').property('bar').eq('baz')
chai
's properties are prior to your object's
obj = { a: { property: '' } }
// you can't do
obj.should.have.a.property
// instead, fallback to old style
obj.should.have.deep.property('a.property')
and
(goes back to the last have/has)
obj = { foo: { bar: '' },
baz: { qux: 11 } }
obj.should.have.foo.bar.with.a('string')
.and.baz.qux.eq(11)
without
(negates)
obj = { foo: {} }
obj.should.have.foo.without.bar
=
(equals)
obj = { foo: { bar: 'baz' } }
obj.should.have.foo.bar= 'baz'
not=
(not.equals)
obj = { foo: { bar: 'baz' } }
obj.should.have.foo.bar.not= 'qux'
long live the chain
response =
status: 200
body:
data:
count: 1
items: [
{ name: 'party pooper' }
]
response.should.have.status.which.eq(200)
.and.body.without.error
.and.body.data.has.count.above(0)
.and.items[0].name= 'party pooper'