Last active
October 23, 2023 14:52
-
-
Save thomashagstrom/e5bffe6c3e3acec592201b6892226af2 to your computer and use it in GitHub Desktop.
Mock for single test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Auth } from 'aws-amplify'; | |
import GetJwtToken from './GetJwtToken'; | |
describe('jwt', () => { | |
describe('GetJwtToken', () => { | |
it('Original mock for Auth class', async () => { | |
const result: Error = (await GetJwtToken()) as Error; | |
expect(result.message).toBe('Could not get session'); | |
}); | |
it('Single function mock of `Auth.getIdToken` using spyOn', async () => { | |
const spy = jest.spyOn(Auth, 'currentSession').mockImplementation(() => ({ | |
getIdToken: () => ({ | |
getJwtToken: () => '123', | |
}), | |
})); | |
const result = await GetJwtToken(); | |
expect(result).toBe('123'); | |
spy.mockRestore(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment