Jest tests for <RaAmplifyAuthProvider /> & related hooks
mayteio opened this issue · 0 comments
mayteio commented
Test coverage possible via hooks, use @testing-library/react-hooks
.
useAuth()
- test error when not inside provider. Potentially refactor to
checkContext
function and isolate that test. - Mock
@aws-amplify/Auth
and test value returned is equal to mocked value.
useAuthProvider()
- mock Auth with jest.fn() for each method called
- test each method is called when the authProvider method is called
- login - test
Auth.signIn
called with username & password - login - test
Auth.federatedSignIn
called withprovider
property - getPermissions - test Promise resolves to [claims: {}, identityId: ""] based on mocks
useUser()
- test undefined return in unauthenticated state
- mock signIn and check returned user value is {}
- mock signOut and check returned value is undefined
- note:
@aws-amplify/Hub
may not need to be mocked as it's a local event bus