Skip to content

Commit a909b5a

Browse files
committed
extend screenshot example with saving
more docs for readme add tests for complex url parameter
1 parent 8d903f5 commit a909b5a

File tree

4 files changed

+541
-466
lines changed

4 files changed

+541
-466
lines changed

__tests__/client.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ describe('scrape', () => {
145145
expect(mockedAxios.request).toHaveBeenCalledTimes(1);
146146
});
147147

148+
it('GET complex urls', async () => {
149+
const url = 'https://httpbin.dev/anything/?website=https://httpbin.dev/anything';
150+
mockedAxios.request.mockImplementation(async (config) => {
151+
// Ensure the URL matches the pattern
152+
expect(config.url).toMatch(client.HOST + '/scrape');
153+
expect(config.method).toEqual('GET');
154+
expect(config.params.key).toMatch(KEY);
155+
expect(config.params.url).toMatch(url);
156+
expect(Object.keys(config.params)).toEqual(['key', 'url']);
157+
158+
// Return the fake response
159+
return resultFactory({ url });
160+
});
161+
162+
const result = await client.scrape(new ScrapeConfig({ url: url }));
163+
expect(result).toBeDefined();
164+
expect(result.result.content).toBe('some html');
165+
expect(result.config.url).toBe(url);
166+
expect(result.context.asp).toBe(false);
167+
expect(result.uuid).toBe('1234');
168+
// a single request:
169+
expect(mockedAxios.request).toHaveBeenCalledTimes(1);
170+
});
171+
172+
173+
148174
it('POST success', async () => {
149175
const url = 'https://httpbin.dev/json';
150176
mockedAxios.request.mockImplementation(async (config) => {

0 commit comments

Comments
 (0)