Cheat Sheet速查表
跳转到主要内容

Mocha.js 速查表

本文根据 Devhints / Mocha.js 翻译。代码示例及版本范围沿用原文。

BDD

mocha.setup('bdd');

describe('something', function() {
  beforeEach(function() {
  });

  it('should work', function() {
  });
});

异步

it('should save', function(done) {
  var user = new User();
  user.save(function(err) {
    if (err) throw err;
    done();
  });
});

Chai:Shoulds(断言风格)

chai.should();

foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.length(3);
tea.should.have.property('flavors').with.length(3);

另请参阅