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
You were close:
jest.mock('@okta/okta-react', () => ({
useOktaAuth: () => ({
authState: { isAuthenticated: true},
authService: { handleAuthentication: jest.fn() }
})
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With