chai速记

chai速记

https://www.chaijs.com/chai.js

assert

const { assert } = require('chai')
assert(val)
assert.fail(actual, expected)
assert.ok(val)                        // is truthy
assert.equal(actual, expected)        // compare with ==
assert.strictEqual(actual, expected)  // compare with ===
assert.deepEqual(actual, expected)    // deep equal check
assert.isTrue(val)
assert.isFalse(val)
assert.isNull(val)
assert.isNotNull(val)
assert.isUndefined(val)
assert.isDefined(val)
assert.isFunction(val)
assert.isObject(val)
assert.isArray(val)
assert.isString(val)
assert.isNumber(val)
assert.isBoolean(val)
assert.typeOf(/tea/, 'regexp') // Object.prototype.toString()
assert.instanceOf(chai, Tea)
assert.include([ a,b,c ], a)
assert.match(val, /regexp/)
assert.property(obj, 'tea') // 'tea' in object
assert.deepProperty(obj, 'tea.green')
assert.propertyVal(person, 'name', 'John')
assert.deepPropertyVal(post, 'author.name', 'John')
assert.lengthOf(object, 3)
assert.throws(function() { ... })
assert.throws(function() { ... }, /reference error/)
assert.doesNotThrow
assert.operator(1, '<', 2)
assert.closeTo(actual, expected)

bdd

const { expect } = require('chai')
expect(object)
.to.equal(expected)
.to.eql(expected)        // deep equality
.to.deep.equal(expected) // same as .eql
.to.be.a('string')
.to.include(val)
.be.ok(val)
.be.true
.be.false
.to.exist
.to.be.null
.to.be.undefined
.to.be.empty
.to.be.arguments
.to.be.function
.to.be.instanceOf
.to.be.gt(5)  // aka: .above .greaterThan
.to.be.gte(5) // aka: .at.least
.to.be.lt(5)  // aka: .below
.to.respondTo('bar')
.to.satisfy((n) => n > 0)
.to.have.members([2, 3, 4])
.to.have.keys(['foo'])
.to.have.key('foo')
expect(() => { ··· })
.to.throw(/not a function/)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值