应该
chai.should();
foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.lengthOf(3);
tea.should.have.property('flavors')
.with.lengthOf(3);
预期
var expect = chai.expect;
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(tea).to.have.property('flavors')
.with.lengthOf(3);
断言
var assert = chai.assert;
assert.typeOf(foo, 'string');
assert.equal(foo, 'bar');
assert.lengthOf(foo, 3)
assert.property(tea, 'flavors');
assert.lengthOf(tea.flavors, 3);
插件将 Chai 的断言扩展到新的上下文,例如供应商集成和对象构造。 开发人员可以构建自己的插件与社区共享,或者使用插件模式来简化现有测试。
chai-webdriver
特色插件
使用 chai 和 selenium-webdriver 创建富有表现力的集成测试。
chai.use(chaiWebdriver(driver));
driver.get('http://chaijs.com/');
expect('nav h1').dom.to.contain.text('Chai');
expect('#node .button').dom.to.have.style('float', 'left');
由开源提供支持
Chai 托管在 GitHub 上。 有建议或发现错误? 分叉此项目以帮助使 Chai 变得更好。 即使是这个文档网站也是开源的,并且可以进行贡献。