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) 818 B
import { STORAGE_KEY, isLoggedIn } from '../src' describe('isLoggedIn', () => { it('returns false if tokens are not set', async () => { // GIVEN // localStorage is empty localStorage.removeItem(STORAGE_KEY) // WHEN // I call isLoggedIn const result = await isLoggedIn() // THEN // I expect the result to be false expect(result).toEqual(false) }) it('returns true if refresh token 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 isLoggedIn const result = await isLoggedIn() // THEN // I expect the result to be true expect(result).toEqual(true) }) })