2

I have a set of tests in my node/express API. The tests work, but I get a strange error after

"MongoError: topology was destroyed"

I'm not sure there is a problem, seeing as the tests pass. But I'd like to get rid of the error.

Here is the error in full:

Your API is listening on port 8080
  index router
    / GET
      ✓ should return with 400 and error message


  1 passing (40ms)


/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongoose/lib/utils.js:440
        throw err;
        ^
MongoError: topology was destroyed
    at ensureIndex (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongodb/lib/db.js:1123:21)
    at executeOperation (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongodb/lib/utils.js:420:24)
    at Db.ensureIndex (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongodb/lib/db.js:1105:10)
    at ensureIndex (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongodb/lib/collection.js:1761:13)
    at executeOperation (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongodb/lib/utils.js:420:24)
    at Collection.ensureIndex (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongodb/lib/collection.js:1757:10)
    at NativeCollection.(anonymous function) [as ensureIndex] (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:142:28)
    at NativeCollection.create (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongoose/lib/model.js:1107:33)
    at NativeCollection.Collection.doQueue (/Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongoose/lib/collection.js:127:24)
    at /Users/johnseabolt/Desktop/code/JAVASCRIPT/KEEPERS/taco_crawl/taco_crawl_api/node_modules/mongoose/lib/collection.js:88:11
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Here is my test:

'user strict'; 

const {TEST_DATABASE_URL} = require('../config'); 
const {dbConnect, dbDisconnect} = require('../db-mongoose'); 
const chai = require('chai'); 
const chaiHttp = require('chai-http'); 
const { app } = require('../index'); 

// Set NODE_ENV to `test` to disable http layer logs
// You can do this in the command line, but this is cross-platform
process.env.NODE_ENV = 'test';

// Clear the console before each run
process.stdout.write('\x1Bc\n');

const expect = chai.expect; 
chai.use(chaiHttp); 

describe('index router', function() {
    before(function() {
        return dbConnect(TEST_DATABASE_URL); 
    }); 

    after(function() {
        return dbDisconnect(); 
    });

    describe('/ GET', function() {
        it('should return with 400 and error message', function() {
            return chai.request(app)
            .get('/')
            .then(function(res) {
                expect(res).to.have.status(400); 
                expect(res).to.be.json; 
                expect(res.body.message).to.equal('Route not found'); 
            }); 
        }); 
    }); 
}); 
squancy
  • 565
  • 1
  • 7
  • 25
J Seabolt
  • 2,576
  • 5
  • 25
  • 57
  • 1
    Possible duplicate of [mongoError: Topology was destroyed](https://stackoverflow.com/questions/30909492/mongoerror-topology-was-destroyed) – golfadas Jul 21 '18 at 10:41

0 Answers0