jest: Idea: `dontMock` has option to add recursively

I was trying to call dontMock on the joi library (a schema validation library), and I had to add a lot of dontMock commands to get it to work—basically one for every file required in the library, recursively. While this makes sense in many situations, it would sure be nice to be able to tell Jest to dontMock a file and and files it requires.

One option could be something like jest.dontMock( moduleName, [recursive] ), where recursive is a boolean that defaults to false, matching the current behavior. If it is set to true, it would apply dontMock recursively.

Another option might be to base it off of what is being required: it seems to me that calling dontMock on a module in node_modules would usually want a recursive dontMock, whereas most other cases would want the non-recursive variety. Perhaps that API is too confusing.

Thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 25 (9 by maintainers)

Most upvoted comments

Oh I see. Can you upgrade to Jest 12 and let me know if this problem still persists? We fixed something around this issue 😃