mockingoose

A Jest package for mocking mongoose models

UNLICENSE License

Downloads
107.1K
Stars
380
Committers
13

Bot releases are visible (Hide)

mockingoose - Add support for Model.insertMany Latest Release

Published by alonronin over 3 years ago

mockingoose - Remove TypeScript, Support UpdateOne and UpdateMany

Published by alonronin over 3 years ago

I decided to remove typescript since changes in mongoose broke monckingoose without good reason.

now mockingoose works with latest version of mongoose.

closes #68

mockingoose - Update Dependencies

Published by alonronin over 5 years ago

mockingoose - Using function to Mock, Convert to TypeScript

Published by alonronin over 5 years ago

What a release we have, thanx @andreialecu for the great hard work and @stieg for his ideas and comments.

So now you can use a function as your mock.

Also we converted the project to TypeScript so you have now a better intellisense in your editor and of course strong typing and compile type checks.

Welcome @andreialecu as a collaborater!

mockingoose - Save Hook

Published by alonronin almost 6 years ago

Add support to Save Hook #45.

Thanx to @hirochachacha 👍

mockingoose - countDocuments and estimatedDocumentCount support

Published by alonronin almost 6 years ago

Thanx to @sepulvedablanco for PR #43 and #42 added 2 new operators.

mockingoose - Support Aggrregate

Published by alonronin over 6 years ago

Now you can mock the Aggregate framework:

it('should aggregate with promise', () => {
  mockingoose.User.toReturn([{ _id: { accountId: '5aef17c3d7c488f401c101bd' } }], 'aggregate');

  return User
    .aggregate(
      [{
        '$group': {
          '_id': {
            'accountId': '$accountId'
          }
        }
      }])
    .then(result => {
      expect(result).toEqual([{ _id: { accountId: '5aef17c3d7c488f401c101bd' } }]);
    });
});
mockingoose -

Published by alonronin over 6 years ago

This version is deprecated due to forgotten build. Use v2.10.1

mockingoose - Support Model.remove

Published by alonronin over 6 years ago

support remove on Model instance. Thanx to @KevinRLeC on PR #24.

mockingoose - Support mongoose 5

Published by alonronin over 6 years ago

  • Support mongoose 5
  • Remove mongoose.Promise for version 5
mockingoose - Support lean

Published by alonronin over 6 years ago

now mongoose supports mongoose query lean:

it('should lean', () => {
      mockingoose.User.toReturn([{ name: '2' }]);

      return User
        .find()
        .lean()
        .then(result => {
          expect(result[0]).toMatchObject({ name: '2' });
        });
    });

thanx @yonatanhg for the issue.

mockingoose - Supports mongoose.createConnection

Published by alonronin over 6 years ago

mockingoose - Returns Error from mock with `save` operation

Published by alonronin almost 7 years ago

thanks @mikeyGlitz for the issue.

mockingoose - Count Opertor

Published by alonronin almost 7 years ago

Support count operator. Thanks @kevinfez for the issue.

Example

it('should count', () => {
  const count = 2;
  mockingoose.User.toReturn(count, 'count');

  return User.count().then(result => {
    expect(result).toBe(count);
  });
});
mockingoose -

Published by alonronin almost 7 years ago

Connect function returns a Pormise, thanks to @devinus

mockingoose - Mockingoose v2.3.0

Published by alonronin about 7 years ago

Now supports empty responses, thanks to @noamokman for the PR.

mockingoose.User.toReturn([]);

return User
.find()
.then(result => {
  expect(result).toHaveLength(0);
})

or

mockingoose.User.toReturn(null);

return User
.findOne()
.then(result => {
  expect(result).toBeFalsy();
})
Package Rankings
Top 1.76% on Npmjs.org
Badges
Extracted from project README
CircleCI Stargazers repo roster for @alonronin/mockingoose Forkers repo roster for @alonronin/mockingoose
Related Projects