TD;LR Basically as mentioned in the title, how is jest.mock implemented in order to mock ES6 modules?
As stated in the title I am wondering how jest.mock works behind the scene? How is it possible to change the content of one ES6 module from another one? As far as I know this is not possible with JavaScript. I am really wondering what magic is happening by Jest in order to mock modules. I am thankful for every explanation or assumption. References to other resources are also appreciated. I already found Understanding jest mocks which is some kind of start. Unfortunately it does not really provide the level of detail I am interested in. To summarize it, I am not interested in how to use jest.mock, but rather how it is conceptually implemented.