Is there any way to mock a variable inside a function?

681 Views Asked by At

The code works like this

let getToken = await apiCall();

apiCall() calls a few internal functions and populates getToken variable with a token. The problem is, in my tests, I can't seem to populate that variable with anything. It is always undefined and an error gets thrown. Is there any way to populate this variable with a dummy value in a unit test?

EDIT

constructor() {
        this._token = '';
}

I want to inject a value in token via a unit test. I'm trying to use sinon right now.

0

There are 0 best solutions below