I have written a function onLoad() for useEffect(). I used aws-amplify Auth.getCurrentSession(). It cached the exception, but the error is undefined.
async function onLoad() {
try {
//debugger;
let session = await Auth.currentSession();
userHasAuthenticated(true);
setUserGroup(session.accessToken.payload['cognito:groups'][0]);
//get the user group
await getUserGroup();
}
catch(e) {
if (e !== 'No current user') {
// e is undefined
onError(e);
}
}
setIsAuthenticating(false);
}
I also want to test the app.js with
test('renders learn react link', () => {
render(<App/>);
const linkElement = screen.getByText(/welcome/i);
expect(linkElement).toBeInTheDocument();
});
App.js return function
return (
!isAuthenticating && (
<Router>
<div className="App">
.............
</div>
</Router>
)
);
}
The problem is IsAuthenticating() set default value is true. The test can't get the document. What should I do to test the document?