A Jest package for mocking mongoose models
UNLICENSE License
Bot releases are hidden (Show)
Published by alonronin over 3 years ago
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
Published by alonronin over 5 years ago
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!
Published by alonronin almost 6 years ago
Add support to Save Hook #45.
Thanx to @hirochachacha 👍
Published by alonronin almost 6 years ago
Thanx to @sepulvedablanco for PR #43 and #42 added 2 new operators.
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' } }]);
});
});
Published by alonronin over 6 years ago
support remove
on Model instance. Thanx to @KevinRLeC on PR #24.
Published by alonronin over 6 years ago
mongoose.Promise
for version 5Published 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.
Published by alonronin over 6 years ago
Published by alonronin almost 7 years ago
thanks @mikeyGlitz for the issue.
Published by alonronin almost 7 years ago
Support count
operator. Thanks @kevinfez for the issue.
it('should count', () => {
const count = 2;
mockingoose.User.toReturn(count, 'count');
return User.count().then(result => {
expect(result).toBe(count);
});
});
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();
})