3 category: JavaScript libraries
9 expect(x).to.be.equal(y) 〉 assert.equal(x, y) 〉 .to.be.true 〉 jQuery, assertions, TDD and BDD, and other Chai examples.
15 const { assert } = require('chai')
21 assert.fail(actual, expected)
22 assert.ok(val) // is truthy
23 assert.equal(actual, expected) // compare with ==
24 assert.strictEqual(actual, expected) // compare with ===
25 assert.deepEqual(actual, expected) // deep equal check
36 assert.isUndefined(val)
38 assert.isFunction(val)
47 assert.typeOf(/tea/, 'regexp') // Object.prototype.toString()
48 assert.instanceOf(chai, Tea)
49 assert.include([ a,b,c ], a)
50 assert.match(val, /regexp/)
51 assert.property(obj, 'tea') // 'tea' in object
52 assert.deepProperty(obj, 'tea.green')
53 assert.propertyVal(person, 'name', 'John')
54 assert.deepPropertyVal(post, 'author.name', 'John')
58 assert.lengthOf(object, 3)
59 assert.throws(function() { ... })
60 assert.throws(function() { ... }, /reference error/)
65 assert.operator(1, '<', 2)
66 assert.closeTo(actual, expected)
69 See: [Assert API](http://chaijs.com/api/assert/) _(chaijs.com)_
74 const { expect } = require('chai')
81 .to.eql(expected) // deep equality
82 .to.deep.equal(expected) // same as .eql
104 .to.be.gt(5) // aka: .above .greaterThan
105 .to.be.gte(5) // aka: .at.least
106 .to.be.lt(5) // aka: .below
111 .to.satisfy((n) => n > 0)
115 .to.have.members([2, 3, 4])
116 .to.have.keys(['foo'])
122 expect(() => { ··· })
123 .to.throw(/not a function/)
126 See: [BDD](http://chaijs.com/api/bdd/) _(chaijs.com)_
130 .to .be .been .is .that .and .have .with .at .of .same
132 These don't do anything and can be chained.
137 expect(object).not.equal('x')
142 ### Using chai-jquery
146 chai.use(require('chai-jquery'))
153 .have.prop('disabled')
154 .have.css('background')
155 .have.css('background-color', '#ffffff')
160 .have.class('active')
165 .have.html('<em>hi</em>')
195 .to.have('.selector')