I am writing test for my async action in react redux, for sake of addressing just the issue I simplified the code here. Here is my action function:
export function updateUserAuthenticationStatus(){
return function(dispatch){
return axios.get(getLoginStatusUrl())
.then(response => {
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
const store = mockStore();
return store.dispatch(updateUserAuthenticationStatus()).then(()=>{
//expect(store.getActions()[0]).to.eql(expectedActions);
});
});
}).catch(function(response){
});
}
}
So the problem is the function getLoginStatusUrl() which does couple of checks in the cookie and return the appropriate url based on some conditions. So what I want is to mock this function to return for example test.com then I can test my action as follows:
it("", () => {
**here I want to mock getLoginStatusUrl() to return test.com**
nock("test.com")
.get("/")
.reply(200,"test detail");
})
How can I mock the getLoginStatusUrl() to return test.com in this scenario?