1import { URLSearchParams } from 'url'; 2 3import { wrapFetchWithBaseUrl } from '../wrapFetchWithBaseUrl'; 4 5describe(wrapFetchWithBaseUrl, () => { 6 it(`supports relative paths`, async () => { 7 const input = jest.fn(); 8 const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2/'); 9 await next('test', {}); 10 expect(input).toBeCalledWith('https://example.com/v2/test', {}); 11 }); 12 it(`supports relative paths that don't begin with slash`, async () => { 13 const input = jest.fn(); 14 const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2/'); 15 await next('test', {}); 16 expect(input).toBeCalledWith('https://example.com/v2/test', {}); 17 }); 18 it(`supports absolute URLs`, async () => { 19 const input = jest.fn(); 20 const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2'); 21 await next('https://expo.dev/', {}); 22 expect(input).toBeCalledWith('https://expo.dev/', {}); 23 }); 24 it(`appends URLSearchParams to the URL`, async () => { 25 const input = jest.fn(); 26 const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2/'); 27 await next('test', { 28 searchParams: new URLSearchParams({ 29 foo: 'bar', 30 }), 31 }); 32 expect(input).toBeCalledWith('https://example.com/v2/test?foo=bar', expect.anything()); 33 }); 34 it(`does not support non-string URLs`, async () => { 35 const input = jest.fn(); 36 const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2'); 37 expect(() => next({ href: 'foo' }, {})).toThrow(/string URL/); 38 }); 39}); 40