mocha 入门 (mocha quick start)
访问量: 2869
refer to: http://mochajs.org/
mocha很简单。如果你已经有了rspec, unit test等经验的话
$ npm install -g mocha
$ mkdir test
$ vim test/test.js
var assert = require("assert")
describe('lala ', function(){
describe('#ihaha ()', function(){
it('should return -1 when the value is not present', function(){
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
})
})
})
s mocha 或者 $mocha test
Array
#indexOf()
✓ should return -1 when the value is not present
1 passing (7ms)
值得一提的是,mocha 一样有before after,
describe('hooks', function() {
before(function() {
// runs before all tests in this block
})
after(function(){
// runs after all tests in this block
})
beforeEach(function(){
// runs before each test in this block
})
afterEach(function(){
// runs after each test in this block
})
// test cases
})
更逗的是,它的 结果报告做的很有意思。 大家可以自己看一下。