mongoose: Stack overflow when testing with jest

I created a new project where I install the last version 4.8.1. I got the error about promise and use custom one.

export default () => {
  mongoose.Promise = global.Promise;
  mongoose.connect('mongodb://localhost/todoAppRN');
  mongoose.connection
    .once('open', () => console.log('Connected to MongoDb'))
    .on('error', err => console.warn('Warning', err));
};

The error don’t stop but if I go back to version 4.7.7 all work fine.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 55 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Hey, I am also in 4.8.1 and I am getting a similar error. Trying to reproduce in a github repo so you can look at it. The situation is I am trying to save a schema with a subdocument and I recieve this error:

MongooseError {
        errors: 
         { content: 
            RangeError: Maximum call stack size exceeded
                at deferred.reject (/app/node_modules/q/q.js:633:9)
                at new promise (/app/node_modules/q/q.js:684:18)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27
                at new promise (/app/node_modules/q/q.js:682:9)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27
                at new promise (/app/node_modules/q/q.js:682:9)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27
                at new promise (/app/node_modules/q/q.js:682:9)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27
                at new promise (/app/node_modules/q/q.js:682:9)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27
                at new promise (/app/node_modules/q/q.js:682:9)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27
                at new promise (/app/node_modules/q/q.js:682:9)
                at EmbeddedDocument.wrappedPointCut [as validate] (/app/node_modules/mongoose/lib/services/model/applyHooks.js:115:23)
                at EmbeddedDocument._done (/app/node_modules/hooks-fixed/hooks.js:101:24)
                at _asyncsDone (/app/node_modules/hooks-fixed/hooks.js:36:36)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:255:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at _next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at fnWrapper (/app/node_modules/hooks-fixed/hooks.js:186:8)
                at EmbeddedDocument.fn (/app/node_modules/mongoose/lib/schema.js:254:9)
                at EmbeddedDocument._next (/app/node_modules/hooks-fixed/hooks.js:62:30)
                at EmbeddedDocument.proto.(anonymous function) [as $__original_validate] (/app/node_modules/hooks-fixed/hooks.js:108:20)
                at /app/node_modules/mongoose/lib/services/model/applyHooks.js:135:27 },
        message: 'bundleitem validation failed',
        name: 'ValidationError' }

I’ll let you know if I figure anything out or get a github repo up.