Я хочу написать тестовый пример для моего роутера. У меня есть объект const, который я хочу смоделировать во время теста. Как я могу изменить пользовательский объект в тестовом файле.
const user = {
isAuthenticated: true
};
export const PrivateRoute = ({ component: Component, ...rest }) => {
return (
<Route
{...rest}
render={props =>
user.isAuthenticated ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: "/login",
state: { from: props.location }
}}
/>
)
}
/>
);
};
test.js
it("should return login route", () => {
const route = <PrivateRoute path="/" component={()=>{}} />
expect(route)..toMatchSnapshot();
});
it("should return home route", () => {
const route = <PrivateRoute path="/" component={()=>{}} />
expect(route)..toMatchSnapshot();
});