Home > front end >  Jest (NestJS) - How to mock method dependencies?
Jest (NestJS) - How to mock method dependencies?

Time:07-05

In the codes below I am trying to test the "someMethodToTest" method, but the "someDependencyMethod" method should be mocked. However, the demonstrated approach is not working as the exception "I MUST NOT BE CALLED!" is being launched every time I run the tests with Jest...

 FAIL  src/user-files/user-files.service.spec.ts (0.123 s)
  ● SomeClassToTest › test someMethodToTest

    thrown: "I MUST NOT BE CALLED!"

NOTES: I - This is a NestJS application; II - Tests using Jest; III - The code is simplified to facilitate understanding.

I've tried many, many approaches...

QUESTION: What is wrong with the code? Why does the "someDependencyMethod" method keep being called?

  • Related