Recently I upgrade the okta-react library and have transitioned the app to use the new hooks. I am updating my tests now. useOktaAuth()
is undefined
. I want to be able to mock it out so I can test when a user is logged in.
const { authState, authService } = useOktaAuth();
// TypeError: Cannot destructure property `authState` of 'undefined' or 'null'
In order to fix that, I tried mocking the hook by doing:
jest.mock('@okta/okta-react', () => ({
useOktaAuth: () => {
return {
authState: {},
authService: {}
};
}
}));
That isn’t working. I still get Any ideas on how to test these components?
Thanks
isAuthenticated
could go between true and false? This satisfies the requirements of the dependencies but, I can't do it in abeforeEach
orbeforeAll
hook as the test can't find the dependencies within that scope. – Shedevil