2012-12-15 5 views
4

내가 얻을 몽구스가 MongoDB를 위해 연결을 시도 내 모카 시험에서 다음과 같은 오류 : 완료되면모카 몽구스 오류

var cfg = require('../config') 
, mongoose = require('mongoose') 
, db = mongoose.connect(cfg.mongo.uri, cfg.mongo.db) 
, User = require('../models/user') 
, Item = require('../models/item') 
, should = require('should') 
, fakeUser 
, fakeItem; 

mongoose.connection.on('error', function(err){ 
    console.log(err); 
}); 

describe('User', function(){ 
    beforeEach(function(done){ 
     //clear out db 
     User.remove(done); 

    }); 

    after(function(done){ 
     //clear out db 
     User.remove(function(err){ 
      Item.remove(done); 
     }); 
    }); 

}); 

답변

7

닫기 연결 :

여기
Error: Trying to open unclosed connection. 

내 테스트입니다

after(function(done){ 
    //clear out db 
    User.remove(function(err){ 
     Item.remove(function() { 
      mongoose.connection.close(); 
      done(); 
     });   
    }); 
}); 
+0

정상적으로 작동한다고 생각하지만이 테스트보다 더 많은 테스트가 있으므로 어디서 .after()를 넣을지 잘 모릅니다. – chovy

+0

테스트가없는'describe()'에서 모든 테스트를 감싸고'close()'호출을 넣는'after()'블록 (그리고'describe()'블록의 나머지 부분) . – glortho