vendredi 15 septembre 2017

How to access global constant in unit tests with Jest?

I want to mock a global variable and test if it has been called in my function. In my file, I define a global variable "remote" which instanciates a Subject (RxJS library). I just want to test if the next function of Subject has been called with the right parameter "name". However, I can't access the global variable remote in my test file. I tried to mock it in my setup file, but doesn't work.

How can I do that ?

const remote = new Subject();
const analytics = {
  click: (name) => {
    if (name) {
      remote.next(name);
    }
  }
}
module.exports = analytics;

Thanks !

Aucun commentaire:

Enregistrer un commentaire