mochaのサンプルを動かす

Mocha - http://visionmedia.github.com/mocha/

インストール

[rossy@centos6 ~]$ su -
[root@centos6 ~]# npm install -g mocha
[root@centos6 ~]# exit

動作確認

[rossy@centos6 ~]$ mkdir napp
[rossy@centos6 napp]$ mkdir test
[rossy@centos6 napp]$ vi test/test.js

test/test.js

var assert = require("assert")
describe('Array', function(){
  describe('#indexOf()', 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));
    })
  })
})

テストを実行する。個人的にはreporter specの出力が好み。

[rossy@centos6 napp]$ mocha

  ․

  ✔ 1 test complete (2ms)

[rossy@centos6 napp]$ mocha --reporter spec


  Array
    #indexOf()
      ✓ should return -1 when the value is not present 


  ✔ 1 test complete (2ms)