question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocking a populated result

See original GitHub issue

This 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:closed
  • Created 5 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
andreialecucommented, Apr 3, 2019

Try Passport.schema.path('creator', Object); before the findOne() call.

1reaction
adithyakrish3commented, May 27, 2020

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found