Mockgoose helps with testing Mongoose applications by spinning up a mock in-memory database.
Questions tagged [mockgoose]
18 questions
5
votes
2 answers
jest mockgoose - jest did not exit one second after the test run has completed
I have a mongoose model:
var mongoose = require("mongoose");
var transactionSchema = mongoose.Schema({
category: { type: String, required: [true, "Category is required."] },
amount: Number,
comment: String,
tags: Array,
currency:…

Miha Šušteršič
- 9,742
- 25
- 92
- 163
5
votes
0 answers
save and create hanging when using Mockgoose
I am trying to use Mockgoose for my tests. Whenever I call .save or .create on a model, the promise doesn't resolve. I am able to use .find and .findOne with no problems. I'm not sure if I have set up something incorrectly or if I misunderstand how…

LT-
- 371
- 1
- 8
5
votes
2 answers
Mockgoose is downloading 234mb when running mockgoose.prepareStorage
I have a node application with access to mongodb thrown mongoose tested with mocha and mockgoose.
I moved recently to mockgoose 7.0.5.
I followed the getting started on github and upped my mocha timeout to 2 minutes.
Here are my before functions in…

Julien TASSIN
- 5,004
- 1
- 25
- 40
4
votes
0 answers
mongoose.model leaves open handle after jest test
I have the following model:
var mongoose = require("mongoose");
var categories = require("../constants/categories");
var transactionSchema = mongoose.Schema({
category: {
type: String,
required: [true, "Category is required."],
…

Miha Šušteršič
- 9,742
- 25
- 92
- 163
4
votes
2 answers
Mongoose aggregation query fails in Jest/Mockgoose test, works elsewhere
I'm trying to create some tests for my Mongoose models, and I can't figure out how to get the Jest/Mockgoose test to pass for a shorthand query/aggregation pipeline (see below in first code block) that I created to retrieve a random document from…

litel
- 3,790
- 3
- 20
- 29
3
votes
1 answer
Clarifying Mockgoose/Mongoose usage?
I'm currently bound to using Mockgoose/Mongoose for a small NodeJS demo and have some questions about it's purpose and functionalities.
I'm aware that Mockgoose is a non persistent database deployed to memory in order to avoid an actual DB, but does…

Tony Tyrrell
- 131
- 1
- 7
2
votes
1 answer
How to use mockgoose (or any other db mocking) in express app integration test
Using mockgoose in a simple unit test is quite straight-forward. However I'm a bit fuzzy as to how one would go about using mockgoose or other mocking solutions in an acceptance or integration test.
Given a simple express/MongoDB app like the…

snowfrogdev
- 5,963
- 3
- 31
- 58
2
votes
1 answer
Chai http - double callback issue
I have a normal unit test for my REST api using chai-http. It fails with following error
warn: double callback!
error: { SyntaxError: Unexpected token { in JSON at position 58
at Object.parse (native)
at IncomingMessage.…

sidgate
- 14,650
- 11
- 68
- 119
1
vote
1 answer
Timeout when using Mockgoose/Mongoose save/create with Mocha and Chai-Expect
I am getting Timeout running Unit Tests with Mocha, Chai and Mockgoose
I have a function Assessment.NewAssessment(assessmentDetails) that will save the assessment in the DB.
NOTE: `Assessment.NewAssessment returns a promise (It is an async…

Ali Elkhateeb
- 3,413
- 4
- 21
- 39
1
vote
3 answers
NodeJS mockgoose save model does not seem to work
Trying to unit test my small api, I need to test the save errors and successes (already signed up, etc).
Currently here is my code:
models/auth.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var AuthSchema = Schema({
id:…

Ederico Rocha
- 250
- 4
- 10
1
vote
1 answer
Mocha test hangs when comparing mongoose object with an object
I'm using mocha and chai (with chai-as-promised) and I'm trying to test a mongoDB database using mockgoose.
The model:
var Campaign = new Schema({
//Schema here
});
Campaign.statics.getOneById = function(id) {
return this.findOne({_id: id…

dabn
- 33
- 1
- 5
0
votes
0 answers
Mocha and Chai is giving error of not calling done() even after it is called
I have few test cases to test the REST API and everything is in Typescript. I am also using docker to dockerize my application. I have 3 containers which are REST_API_app, MongoDB, api_testing_container. I create the container api_testing_container…

Yatin Gaikwad
- 1,140
- 1
- 13
- 23
0
votes
2 answers
Jest Mockgoose Doc.save() doesn't work async/await
I'm using jest on my e-commerce software so I can also do render tests when end-to-end testing (themes are supported, that's why).
But I'm currently just testing some mongoose functionality and when I'm trying to save a document, it gives me this…

CherryNerd
- 1,258
- 1
- 16
- 38
0
votes
0 answers
mockgoose.helper.reset() does not delete database
I am creating the unit test in Node.Js using Mocha.
In this application, MongoDB is used. To mock MongoDB, I am using Mockgoose.
Following is the code
before(function (done) {
mockgoose.prepareStorage().then(function () {
…

Twix
- 392
- 1
- 12
- 38
0
votes
0 answers
Create db connection with Mockgoose inside docker container
I have two docker containers, one for the database and another one for the API.
I am trying to do some test in API and I need to use monckgoose.
I can create a succesfully connection with mongoose, but I get MongoError: Authentication failed. when I…

Diego
- 304
- 1
- 8