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.
I encountered the same problem in jest
tests. What helped me is the resetModules call before test cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With