0

I mock a javascript class in a file using jest.mock('./blabla.js'). The file blabla.js exports a new instance of the class when imported per default (export default new BlaBla()). That class has several methods in it. I want to use original implementation of just one (or some) of these methods, but I want to continue using mocks of other methods. Is it ever possible on jest?

There is a similar question asked for nodejs here: Jest: How to mock one specific function when using module.exports. But if I tried to adapt this solution to my test spec, it simply didn't work.

schlingel
  • 1,514
  • 2
  • 15
  • 24
  • Either the BlaBla instance is a collaborator that should be replaced with a test double or part of the implementation that shouldn't. Don't go halves; split it into separate components, if the different treatment is really needed. – jonrsharpe Apr 16 '21 at 19:03
  • Why the solution didn't work? Show the code to reproduce your issue and the error you got. – Lin Du Apr 19 '21 at 03:08
  • You can mock specific methods on class `prototype`, this doesn't require the use of jest.mock. – Estus Flask Apr 19 '21 at 05:30

0 Answers0