describe('User', function(){
describe('#save()', function(){
it('should save without error', function(done){
^^^^ look, there! ;-)
var user = new User('Luna');
user.save(function(err){
if (err) throw err;
done();
});
})
})
})
It's a function passed by Mocha when it detects that the callback you pass to it()
takes an argument.
EDIT: here is a very simple standalone demo implementation of how it()
could be implemented:
var it = function(message, callback) {
console.log('it', message);
var arity = callback.length; // returns the number of declared arguments
if (arity === 1)
callback(function() { // pass a callback to the callback
console.log('I am done!');
});
else
callback();
};
it('will be passed a callback function', function(done) {
console.log('my test callback 1');
done();
});
it('will not be passed a callback function', function() {
console.log('my test callback 2');
// no 'done' here.
});
// the name 'done' is only convention
it('will be passed a differently named callback function', function(foo) {
console.log('my test callback 3');
foo();
});
Output:
it will be passed a callback function
my test callback 1
I am done!
it will not be passed a callback function
my test callback 2
it will be passed a differently named callback function
my test callback 3
I am done!