Something went wrong. Try again.
TypeScript client for accessing TLE Community.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import { getLacuna } from '../__utils__/get-lacuna';import Lacuna from '../lacuna';import type { ResponseEvent } from './responses';
let lacuna: Lacuna;
beforeAll(async () => { lacuna = await getLacuna();});
test('publishes every response to onResponse subscribers', async () => { const seen: ResponseEvent[] = []; const unsubscribe = lacuna.onResponse((event) => { seen.push(event); });
const { result } = await lacuna.captcha.fetch(); unsubscribe();
expect(seen).toHaveLength(1); expect(seen[0].request.module).toBe('captcha'); expect(seen[0].request.method).toBe('fetch'); expect(seen[0].request.addSession).toBe(true); expect(seen[0].attempt).toBe(0); expect(seen[0].retry).toEqual(expect.any(Function)); expect(seen[0].response.result).toEqual(result);});
test('onResponse unsubscribe stops further events', async () => { const handler = jest.fn(); lacuna.onResponse(handler)();
await lacuna.captcha.fetch();
expect(handler).not.toHaveBeenCalled();});
test('publishes errors with the request that caused them', async () => { const seen: ResponseEvent[] = []; const unsubscribe = lacuna.onResponse((event) => { seen.push(event); });
const { error } = await lacuna.captcha.solve({ guid: 'test', solution: 'test' }); unsubscribe();
expect(error).toBeDefined(); expect(seen).toHaveLength(1); expect(seen[0].request.method).toBe('solve'); expect(seen[0].response.error).toEqual(error);});