Mockgoose错误:关闭ENOTCONN

时间:2015-11-01 19:12:49

标签: javascript node.js mongoose mocha

这让我很生气。

我正在使用以下设置运行一些单元测试

import mongoose from "mongoose";
import mockgoose from "mockgoose";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";

import entryModel from "../entryModel";
import entrySchema from "../../../schemas/entry/entrySchema";

chai.use(chaiAsPromised);

mockgoose(mongoose);

mongoose.connect('mongodb://localhost/test');

当我通过命令行运行时,我得到了它。

  

1)预期的功能"在每个"之前钩:        未捕获错误:关闭ENOTCONN         at exports._errnoException(util.js:837:11)         在Socket.onSocketFinish(net.js:211:26)         在emitNone(events.js:72:20)         在Socket.emit(events.js:166:7)         在finishMaybe(_stream_writable.js:468:14)         at endWritable(_stream_writable.js:478:3)         在Socket.Writable.end(_stream_writable.js:443:5)         在Socket.end(net.js:400:31)         在Socket.onend(_stream_readable.js:490:10)         在Socket.g(events.js:260:16)         在emitNone(events.js:72:20)         在Socket.emit(events.js:166:7)         at endReadableNT(_stream_readable.js:893:12)         at doNTCallback2(node.js:429:9)         at process._tickCallback(node.js:343:17)

但是,如果我使用gulp-mocha运行它们,我会得到相同的错误,但测试仍以某种方式运行。

任何人都可以帮帮我!?

1 个答案:

答案 0 :(得分:0)

你能尝试把这行

mongoose.connect();

之前:

mockgoose(mongoose);

这解决了同样的问题。