4.1.1
I'm trying to unit test a simple component that redirects the user to a location or the login page whether he has permissions or not.
I don't understand how to unit test it. I've asked the internet and stack overflow without success.
My simple component:
const AppContainer = ({ location }) =>
(isUserAuthenticated()
? <AppWithData />
: <Redirect
to={{
pathname: "/login",
state: { from: location }
}}
/>);
My attempt of unit test:
```
function setup() {
const enzymeWrapper = mount(
);
return {
enzymeWrapper
};
}
jest.mock("lib/authAPI", () => ({
isUserAuthenticated: jest.fn(() => false)
}));
describe("AppContainer component", () => {
it("renders redirect", () => {
const { enzymeWrapper } = setup();
expect(enzymeWrapper.find("<Redirect />")).toBe(true); // I know it's wrong but it's my best bet
});
});
```
Cheers
Luca
If you have a documentation suggestion, a PR is really the only way of effectively discussing such things.
@timdorr Creating a PR to document something you cannot get to work doesn't make any sense. The example and explanation is a very clear and concise example, and @duvet86 explained that other avenues of assistance didn't pan out. Can you or another contributor provide some info to help this poor soul out?