import browser from './scripts/browser'; import { cleanup } from './scripts/cleanup'; import { compileWithTypescript } from './scripts/compileWithTypescript'; import { copyAsset } from './scripts/copyAsset'; import { generateClient } from './scripts/generateClient'; import server from './scripts/server'; describe('v2.fetch', () => { beforeAll(async () => { cleanup('v2/fetch'); await generateClient('v2/fetch', 'v2', 'fetch'); copyAsset('index.html', 'v2/fetch/index.html'); copyAsset('main.ts', 'v2/fetch/main.ts'); compileWithTypescript('v2/fetch'); await server.start('v2/fetch'); await browser.start(); }, 30000); afterAll(async () => { await browser.stop(); await server.stop(); }); it('requests token', async () => { await browser.exposeFunction('tokenRequest', jest.fn().mockResolvedValue('MY_TOKEN')); const result = await browser.evaluate(async () => { const { OpenAPI, SimpleService } = (window as any).api; OpenAPI.TOKEN = (window as any).tokenRequest; return await SimpleService.getCallWithoutParametersAndResponse(); }); expect(result.headers.authorization).toBe('Bearer MY_TOKEN'); }); it('supports complex params', async () => { const result = await browser.evaluate(async () => { const { ComplexService } = (window as any).api; return await ComplexService.complexTypes({ first: { second: { third: 'Hello World!', }, }, }); }); expect(result).toBeDefined(); }); });