Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should fetch with a token', async () => {
fetch.__setResponse('{"foofoo":"barbar"}');
const results = await get('https://github.com', { token: 'TEST_TOKEN' });
expect(fetch)
.toBeCalledWith('https://github.com', {
headers: {
'User-Agent': 'zel',
'Authorization': 'token TEST_TOKEN',
},
});
expect(results)
.toBe('{"foofoo":"barbar"}');
});
it('should handle rejections', async () => {
fetch.__setShouldReject(true);
fetch.__setResponse('THIS IS A REJECTION');
try {
await get('https://rejected.com');
} catch (err) {
expect(err).toBe('THIS IS A REJECTION');
}
});
});
it('should fetch data from a remote server', async () => {
fetch.__setResponse('{"foo":"bar"}');
const results = await get('https://google.com');
expect(fetch)
.toBeCalledWith('https://google.com', {
headers: {
'User-Agent': 'zel',
},
});
expect(results)
.toBe('{"foo":"bar"}');
});