Questions tagged [mockingoose]

Use the [mockingoose] tag for question-related to the mockingoose package

A Jest package for mocking mongoose models

11 questions
4
votes
3 answers

TypeError: (0 , _mockingoose.default) is not a function _ mockingooose

I am trying to mock my mongoose schemas.with this code : // report.schema.js import mongoose, { Schema } from 'mongoose'; const reportSchema = new Schema( { data:{ type: string }, }, { timestamps: true } ); export default…
Babak Abadkheir
  • 2,222
  • 1
  • 19
  • 46
2
votes
0 answers

mockingoose does not work with TypeScript

The following import import mockingoose from 'mockingoose'; gives an error Could not find a declaration file for module 'mockingoose'. with TypeScript. According to this npm page, mockingoose provides its own type definitions, so you don't need…
VIVID
  • 555
  • 6
  • 14
2
votes
1 answer

Mockingoose _id: Cannot read property 'where' of undefined error

I have a simple express routine to save incoming data: app.post('/news', async (req, res, next) => { const news = await model.create(req.body); res.status(201).json(news); }); And I want to write unit test for this by using mockingoose and…
Murat Çorlu
  • 8,207
  • 5
  • 53
  • 78
2
votes
0 answers

Mongoose queries return undefined when importing Mockingoose

Hello guys and thank you for your time. I am testing with jest, using mongo memory server and mongoose schema. One of my tests require me to use mockingoose, however from the point that i import mockingoose (import mockingoose from 'mockingoose')…
1
vote
1 answer

In mockingoose, how do I mock a call to "find" without having "undefined" returned?

I'm using mockingoose 2.13.2 and mongoose 5.12.2 with Typescript and jest. In my test, I'm trying to mock a call to my schema's find method, so I tried the below import mockingoose from 'mockingoose'; ... beforeEach(async () => { …
Dave
  • 15,639
  • 133
  • 442
  • 830
0
votes
0 answers

How to get id model constructor mockingoose jest

How to predict _id in jest test using mockingoose const newUser = new User({ username: username, name, email: email, password: password, }) how to know what id will new User() return const user = { id: 'a' username:…
kennarddh
  • 2,186
  • 2
  • 6
  • 21
0
votes
1 answer

Why test are frezing when trying to mock mongoose model by mockingoose?

I have next Card model export class Card extends Document { @Prop({ required: true, immutable: true}) id: string; @Prop({ required: true }) name: string; ... export const CardSchema = SchemaFactory.createForClass(Card); } And test are freezing…
0
votes
1 answer

Mock tests doesn't fail

I'm making some tests using mookingose but they always pass even when showing some errors on the console, This is an example of one of the tests import mockingoose from 'mockingoose'; import { getUserById, insertUser } from…
Delm
  • 67
  • 1
  • 9
0
votes
0 answers

How to access the update and options part when using findOneAndUpdate?

I have a service that uses the findByIdAndUpdate (which uses findOneAndUpdate under the hood), which I need to test. The problem is that as far as I can tell, the finderMock function that I pass to the toReturn method get called with just the…
ethanfar
  • 3,733
  • 24
  • 43
0
votes
2 answers

How do you use distinct with mockingoose?

I'm using Mockingoose to mock my mongoose calls when running tests with Jest. I tried this but I get an error mockingoose.Account.toReturn( ["593cebebebe11c1b06efff0372","593cebebebe11c1b06efff0373"], "distinct" ); Error:…
Dev01
  • 13,292
  • 19
  • 70
  • 124
0
votes
1 answer

Need an example for using mockingoose with statics or methods

trying to mock a static mongoose function (getLoginData) with mockingoose with no luck. Does anyone has a working example for me? Here is what i got: My User Model // models/user.js ... UserSchema.methods.login = function (username, password, host)…
Remownz
  • 417
  • 1
  • 4
  • 18