我正在为我的异步操作编写测试,以处理简单的代码。这里是我的动作功能:模拟在另一个函数中使用的函数
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){
});
}
}
所以问题是功能getLoginStatusUrl(),它确实对夫妇检查的cookie,并返回基于某些条件下,适当的URL。所以,我要的是嘲笑这个函数返回例如test.com然后我可以测试我的行动如下:
it("",() => {
**here I want to mock getLoginStatusUrl() to return test.com**
nock("test.com")
.get("/")
.reply(200,"test detail");
})
我怎么能嘲笑getLoginStatusUrl()在这种情况下返回test.com?
非常感谢您的回答,我会开始研究它并让您知道结果。只是一个问题:我有一个getLoginStatusUrl函数来获取url,我们根本不知道路径,但是在这里我们有onGet('/ loginStatus')模拟函数,我们定义路径'/ loginStatus'它如何解决这个问题? –
@HamedMinaee看到编辑。 –
非常感谢我正在处理它,并让你知道结果 –