Can't connect to mongoose and mockgoose

I'm trying to use mockgoose (2.0.3) with mongoose (4.0.2) so that I can run my block tests without a mongo server.

And as far as I can tell, I'm using it correctly

import mockgoose from "mockgoose";
import mongoose from "mongoose";

let mongooseMock = mockgoose(mongoose);

      

Then I pass the mongoose instance to my module which calls the schema

But when I run my test I get

{ [MongoError: mock: connect failed] name: 'MongoError', code: 13328 }

      

And I have no idea why, it should just work out of the box.

+3


source to share


2 answers


I just ran into the same problem. You should call mongoose#connect(url)

after mockgoose(mongoose)

, but before running any tests.

Specifically, I created a new module



var mockgoose = require("mockgoose");
var mongoose = require("mongoose");

mockgoose(mongoose);

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

module.exports = mockgoose;

      

and require

at the top of each test file using mockgoose. I have not tried it with es6 syntax, but I think the main problem remains when called connect

whether you are using require

or import

.

+3


source


It turns out it has something to do with the mockgoose version. I used the latest experimental build 5.0.0-rc.5

when I had to use the latest official build.



+1


source







All Articles