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

Mocha.js TDD 接口 速查表

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

TDD

mocha.setup('tdd');

suite('something', function() {
  setup(function() {
  });

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

  teardown(function() {
  });
});

异步

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

Chai:Expect(断言风格)

var expect = chai.expect;

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

另请参阅