如何测试history.push内部动作?

时间:2019-03-15 16:57:01

标签: reactjs redux jestjs enzyme redux-thunk

如何测试history.push内部动作?

std::map<ComponentID,std::vector<std::unique_ptr<Component>>>

};

export const startLogout = () => {
return ( dispatch ) => {

    return firebase
        .auth()
        .signOut()
        .then(() => {
            dispatch( logout() );
            history.push( '/login' );
        })
        .catch( ( err ) => {
            // Simple redirect to non existent route
            history.push( '/oops' );
            console.log( err );
        });
};

});

此当前代码给我这个错误:

预期的上次调用模拟函数:         [“/登录”]       但是它没有被调用。

谢谢

1 个答案:

答案 0 :(得分:0)

您正在创建本地history对象,并将其push属性设置为间谍,然后再测试是否调用了本地history.push间谍。

您需要在history.push中使用的startLogout上创建间谍,并且必须在 派发startLogout操作之前将其放置在适当的位置。 / p>

相关问题