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.
source to share
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
.
source to share