Open brandondurham opened 4 years ago
The library is quite simple and is meant to be a drop-in replacement for Amplify Auth as you would use it for Cognito User Pool authorization. It allows you to use your front end running with a server-less-offline back end.
An example of it being used is here: https://github.com/fourTheorem/slic-starter/blob/master/frontend/src/auth-provider.js Associated redux action creators are here: https://github.com/fourTheorem/slic-starter/blob/master/frontend/src/actions/auth.js
Hope this helps.
I get: "Auth.currentAuthenticatedUser is not a function" error.
My setup is just:
import Auth from 'mock-amplify-auth'
I see Auth.currentSession()
used in the example above.
Does this mean currentAuthenticatedUser()
is not supported, or am I using it wrong?
Correct me if I am wrong @eoinsha, however, if using jest you'd do something like this;
import mockAuth from 'mock-amplify-auth'
jest.mock('@aws-amplify/auth', mockAuth);
test('should', () => {
// ...
})
If you want to extend it for currentAuthenticatedUser (we need to mock completeNewPassword
), do so before running jest.mock
:
import mockAuth from 'mock-amplify-auth';
// build your mocks - you could use `mockAuth` if you need access to internal state.
// personally, I only need jest.fn()
const mockMissingAuthFunctions = {
completeNewPassword: jest.fn(),
currentAuthenticatedUser: jest.fn()
}
jest.mock('@aws-amplify/auth', () => ({
...mockAuth,
...mockMissingAuthFunctions
}))
test('should', () => {
// ...
})
Here's how I did it using Jest
import mockAuth from 'mock-amplify-auth';
jest.mock('aws-amplify', () => ({
Auth: {
...mockAuth,
}
}));
does exist @types/mock-amplify-auth?
I’m not entirely sure how to use these. Is there any documentation you can share?