Presentation by Felipe F. Lima / @felipefdlima
browser support
simple async support
string diff support
javascript API for running tests
auto-detects and disables coloring for non-ttys
reports test durations
highlights slow tests
file watcher support
node debugger support
use any assertion library you want
proper exit status for CI support etc
maps uncaught exceptions to the correct test case
async test timeout support
test-specific timeouts
growl notification support
global variable leak detection
optionally run tests that match a regexp
auto-exit to prevent "hanging" with an active loop
easily meta-generate suites & test-cases
mocha.opts file support
clickable suite titles to filter test execution
detects multiple calls to done()
use any assertion library you want
extensible reporting, bundled with 9+ reporters
extensible test DSLs or "interfaces"
before, after, before each, after each hooks
arbitrary transpiler support (coffee-script etc)
TextMate bundle
...
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));
});
});
});
describe('User', function(){
describe('#save()', function(){
it('should save without error', function(done){
var user = new User('Luna');
user.save(function(err){
if (err) throw err;
done();
});
});
});
});
describe('Connection', function(){
var db = new Connection,
tobi = new User('tobi'),
loki = new User('loki'),
jane = new User('jane');
beforeEach(function(done){
db.clear(function(err){
if (err) return done(err);
db.save([tobi, loki, jane], done);
});
});
describe('#find()', function(){
it('respond with matching records', function(done){
db.find({ type: 'User' }, function(err, res){
if (err) return done(err);
res.should.have.length(3);
done();
});
});
});
});
1. You need NODE.JS
2. You need Mocha
npm install -g mocha
3. And run
mocha test.js
4. By default mocha will use the pattern "./test/*.js", so it's usually a good place to put your tests.
mocha
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="jquery.js"></script>
<script src="expect.js"></script>
<script src="mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test.array.js"></script>
<script src="test.object.js"></script>
<script src="test.xhr.js"></script>
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
</script>
</body>
</html>
should.js BDD style shown throughout these docs
expect.js expect() style assertions
better-assert c-style self-documenting assert()
chai expect(), assert() and should style assertions
...
Mocha have any type of reports
And for use:
mocha -R spec
For see all available:
mocha --reporters
mocha -R dot

mocha -R list

mocha -R progress

mocha -R json

mocha -R spec

mocha -R landing

mocha -R nyan

And when failure?
The airplane down!

Or show a boring list


| Express | Connect |
| SuperAgent | WebSocket.io |
| Mocha |
Thank you