Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node TypeScript delete require cache

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.

like image 342
Lehks Avatar asked Oct 14 '25 02:10

Lehks


1 Answers

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

like image 195
Kamil Chmielewski Avatar answered Oct 16 '25 16:10

Kamil Chmielewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!