You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now I use db.js module within my tests in the following way
//foobar.spec.jsconstdb=require('./db');describe('foo',()=>{beforeEach(()=>db.connect());afterEach(()=>db.close());it('is some test',async()=>{expect(awaitdb.mycol.find({_id: 'foo'})).toBeNull();});it('is some other test',async()=>{expect(awaitdb.mycol.find({_id: 'bar'})).toBeNull();});});
The second test will fall with an error MongoError: topology was destroyed because the connection will be closed after first test but not be opened anew before second test.
It is happen because Database#connect method always try to return the old connection even if it was be closed.
I think we should set this.connection to equal null within Database#close method about like this
returnthis.client.close(force).then(()=>this.connection=null).catch((e)=>{// Ignore thisdebug(`Could not close the connection due to error "${e.message}" ${e.stack}`);});
The text was updated successfully, but these errors were encountered:
I have created
db.js
module with codeNow I use
db.js
module within my tests in the following wayThe second test will fall with an error
MongoError: topology was destroyed
because the connection will be closed after first test but not be opened anew before second test.It is happen because
Database#connect
method always try to return the old connection even if it was be closed.I think we should set
this.connection
to equalnull
withinDatabase#close
method about like thisThe text was updated successfully, but these errors were encountered: