How to use the node-fetch.__setResponse function in node-fetch

To help you get started, we’ve selected a few node-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vutran / zel / __tests__ / utils.js View on Github external
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"}');
        });
github vutran / zel / __tests__ / utils.js View on Github external
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');
            }
        });
    });
github vutran / zel / __tests__ / utils.js View on Github external
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"}');
        });