Mocking a populated result
See original GitHub issueThis issue is the as #38.
It was said:
it is not suppose to populate as it is just a mock, so if you use populate, mock the complete result
However, when I mock the populated result it returns a version without the field that is wanting to be ‘populated’.
Example:
mockingoose.Passport.toReturn({
name: 'test',
creator: { password: '123'},
}, 'findOne');
Passport.findOne({ accessId })
.populate('creator')
.exec((err, passport) => {
console.log(passport); // => { name:'test' }
})
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (11 by maintainers)
Top Results From Across the Web
Mock Mongoose Objects after populate call - Stack Overflow
I am trying to mock a populate call and I would like to mock to return mongoose objects, not plain JS objects. sandbox.mock(BookModel)...
Read more >Mockito mock examples - DigitalOcean
This is the simplest way to mock an object. We are using JUnit 5 to write test cases in conjunction with Mockito to...
Read more >Advanced workflows - Mocking and testing - AWS Amplify Docs
Learn how to quickly test and debug without pushing all changes in your Amplify project to the cloud. Use local mocking and testing...
Read more >Mocking schema capabilities - Apollo GraphQL Docs
The description field is populated entirely locally, so including it in network requests isn't helpful. The description field isn't in our server-side schema ......
Read more >Mocking local variables within the method-under-test - Telerik
Thanks again for bringing the question. Out parameter is set as expected value which is basically a result value to be assigned once...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try
Passport.schema.path('creator', Object);
before thefindOne()
call.Hello,
Sorry for being late to the party. What is the fix here? How to mock .populate() in the already mocked result? Can someone please explain?