Express API Chai测试 - MongoError:拓扑被破坏

时间:2018-06-11 15:26:05

标签: javascript express chai

我的node / express API中有一组测试。测试工作,但我在

后得到一个奇怪的错误
  

" MongoError:拓扑被破坏"

我不确定是否有问题,看到测试通过了。但是我想摆脱这个错误。

以下是完整错误:

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)

以下是我的测试:

'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'); 
            }); 
        }); 
    }); 
}); 

0 个答案:

没有答案