UNPKG

axios-refresh-me

Version:

Axios wrapper for refresh token and retry request

4 lines (2 loc) 1.47 kB
import { a } from './chunk-FHDVOBTX.mjs'; describe("RequestObserver",()=>{let e;beforeEach(()=>{e=new a({refreshHandler:jest.fn().mockResolvedValue("newToken"),combineAbortSignals:!0,statusCodes:[401],retryCount:1});}),test("combineSignals should combine signals when combineAbortSignals is true",()=>{let n=new AbortController().signal,s=e.combineSignals(n);expect(s).toBeInstanceOf(AbortSignal);}),test("combineSignals should return observer signal when combineAbortSignals is false",()=>{e=new a({refreshHandler:jest.fn().mockResolvedValue("newToken"),combineAbortSignals:!1,statusCodes:[401],retryCount:1});let n=new AbortController().signal,s=e.combineSignals(n);expect(s).toBe(e.abortController.signal);}),test("subscribe should add a listener to the suspendedQueue",async()=>{e.subscribe(),expect(e.suspendedQueue.size).toBe(1);}),test("notify should notify all listeners and clear the suspendedQueue",()=>{let n=jest.fn();e.suspendedQueue.add(n),e.notify(),expect(n).toHaveBeenCalled(),expect(e.suspendedQueue.size).toBe(0);}),test("exchangeToken should refresh token and notify listeners",async()=>{let n=jest.fn();e.suspendedQueue.add(n),await e.exchangeToken(),expect(n).toHaveBeenCalled(),expect(e.suspendedQueue.size).toBe(0);}),test("baseRequestIntercept should intercept request and combine signals",async()=>{let n={_retryCount:0,signal:new AbortController().signal},s=await e.baseRequestIntercept(n);expect(s.signal).toBeInstanceOf(AbortSignal);});});