Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest tests for <RaAmplifyAuthProvider /> & related hooks #4

Open
mayteio opened this issue Mar 18, 2020 · 0 comments
Open

Jest tests for <RaAmplifyAuthProvider /> & related hooks #4

mayteio opened this issue Mar 18, 2020 · 0 comments

Comments

@mayteio
Copy link
Owner

mayteio commented Mar 18, 2020

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 with provider 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
@mayteio mayteio changed the title Unit tests for <RaAmplifyAuthProvider /> & related hooks Jest tests for <RaAmplifyAuthProvider /> & related hooks Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant