How to mock mongoose model method with TypeMoq?

158 Views Asked by At

I tried with

const mock = TypeMoq.Mock.ofInstance(userModel)
mock
    .setup(x => x.findOne(TypeMoq.It.isAny()))
    .returns(() => ({username: 'test', gender: 'female'}))

But it doesn't work.

  • It claims that userModel doesn't have an findOne method
  • The returns won't pass compilation because {username: 'test', gender: 'female'} is not a DocumentQuery object.
0

There are 0 best solutions below