How to use mongoose in mocha unit test?

I feel very confused, how to unit test involves mongodb in mocha, I still can not successfully call the save function with no exception is thrown.

I try to use the most simple example for testing and found that there are still problems.Here is my code .

var assert = require("assert")
var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/dev', function(err){
  if(err) throw err
});

describe('increment Id', function(){
  describe('increment', function(){
    it('should has increment', function(){


      var Cat = mongoose.model('Cat', { name: String });

      var kitty = new Cat({ name: 'Zildjian' });
      kitty.save(function (err) {
        if (err) throw err
        console.log('meow');
      });

    })
  })
})

This code does not throw an exception, but there is no data updated or created in the mongodb .

> show collections
pieces
sequences
system.indexes

You're running your test synchronously.

To execute async test you should add callback function:

it('should has increment', function(done){
  var Cat = mongoose.model('Cat', { name: String });
  var kitty = new Cat({ name: 'Zildjian' });
  kitty.save(function (err) {
    if (err) {
      done(err);
    } else {
      console.log('meow');
      done();
    }
  });
})

or simply

it('should has increment', function(done){
  var Cat = mongoose.model('Cat', { name: String });
  var kitty = new Cat({ name: 'Zildjian' });
  kitty.save(done);
})