Jasmine Unit Tests won't end gracefully after a mongoose.connect

217 views
Skip to first unread message

Matt Johansen

unread,
Dec 14, 2013, 11:30:46 PM12/14/13
to mongoo...@googlegroups.com
Having some issues in writing jasmine unit tests that involve mongoose connections. I'm trying to do some variations of :

  beforeEach(function() {
    mongoose.connect('localhost', 'test');
  });

  afterEach(function() {
    mongoose.disconnect();
  });

I've only started adding this to the beforeEach and afterEach blocks when I realized that tests weren't stopping without me going in and Ctrl+C-ing them. Tests pass so the connection is working but it seems that disconnect isn't working properly.

Anybody have experience in this situation or have had similar issues?
Appreciate any feedback.

Cheers,
Matt

Matt Johansen

unread,
Dec 15, 2013, 10:31:04 PM12/15/13
to mongoo...@googlegroups.com
Not the best solution but this works for me now:
after my last it block.

  setTimeout(function() {
    mongoose.disconnect();
 
}, 20000);

Joe Wagner

unread,
Dec 16, 2013, 11:18:28 AM12/16/13
to mongoo...@googlegroups.com
I'm not to familiar with Jasmine, but using mocha you can pass disconnect a callback.

afterEach(function (done) {
 mongoose
.disconnect(done);
});
Reply all
Reply to author
Forward
0 new messages