UNPKG

react-native-axios-jwt

Version:

Axios interceptor to store, transmit, clear and automatically refresh tokens for authentication in a React Native environment

33 lines (26 loc) 893 B
import { STORAGE_KEY, getRefreshToken } from '../src' describe('getRefreshToken', () => { it('returns undefined if tokens are not set', async () => { // GIVEN // localStorage is empty localStorage.removeItem(STORAGE_KEY) // WHEN // I call getRefreshToken const result = await getRefreshToken() // THEN // I expect the result to be undefined expect(result).toEqual(undefined) }) it('returns the access token is it is set', async () => { // GIVEN // Both tokens are stored in localstorage const tokens = { accessToken: 'accesstoken', refreshToken: 'refreshtoken' } localStorage.setItem(STORAGE_KEY, JSON.stringify(tokens)) // WHEN // I call getRefreshToken const result = await getRefreshToken() // THEN // I expect the result to be the supplied refresh token expect(result).toEqual('refreshtoken') }) })