2

I want to re-require a module in TypeScript and Node multiple times for testing. According to this post that should work by using

const config = require('./foo');
delete require.cache[require.resolve('./foo')];

However, this does not work for me. Also, when I print out the object require.cache, it is empty.

Lehks
  • 2,582
  • 4
  • 19
  • 50

1 Answers1

4

I encountered the same problem in jest tests. What helped me is the resetModules call before test cases.

  • 1
    You, man, are the single most awesome person in this planet at this exact moment in the history of humankind. – Luis Sieira Dec 07 '19 at 21:54