How to use the node-fetch.mockReturnValueOnce 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 gnosis / verify-on-etherscan / __tests__ / integration.js View on Github external
test('Filters out verified contracts', async () => {
  const logger = {
    log: jest.fn()
  };

  const verifiedResp = JSON.stringify({ status: '1' });
  const unverifiedResp = JSON.stringify({ status: '0' });
  fetch
    .mockReturnValueOnce(new Response(verifiedResp))
    .mockReturnValueOnce(new Response(verifiedResp))
    .mockImplementation(() => new Response(unverifiedResp));
  logger.log
    .mockReturnValueOnce(new Response(verifiedResp))
    .mockReturnValueOnce(new Response(verifiedResp))
    .mockImplementation(() => new Response(unverifiedResp));

  const { unverified: unverifiedContracts, alreadyVerified } = await filterOutVerified(
    artifactsData,
    { apiUrl, logger }
  );

  expect(fetch.mock.calls).toMatchSnapshot('Fetch calls');

  const fetchReturns = fetch.mock.results.map(({ value: response }) => JSON.parse(response.body));
github huchenme / github-trending-api / src / __tests__ / fetch.js View on Github external
describe('fetchDevelopers()', () => {
  fetch.mockReturnValueOnce({
    text: jest.fn().mockReturnValue(mockDevelopers),
  });

  it('should match snapshot', async () => {
    await expect(fetchDevelopers()).resolves.toMatchSnapshot();
  });
});
github kefranabg / readme-md-generator / src / utils.spec.js View on Github external
it('should return author website url when it exists', async () => {
      const expectedAuthorWebsite = 'https://www.franck-abgrall.me/'
      fetch.mockReturnValueOnce(
        Promise.resolve({
          json: () => Promise.resolve({ blog: expectedAuthorWebsite })
        })
      )

      const githubUsername = 'kefranabg'
      const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername)
      expect(authorWebsite).toEqual(expectedAuthorWebsite)
    })
github Human-Connection / Human-Connection / backend / src / schema / resolvers / embeds.spec.js View on Github external
beforeEach(() => {
        fetch
          .mockReturnValueOnce(Promise.resolve(new Response(pr960)))
          .mockReturnValueOnce(Promise.resolve(JSON.stringify({})))
        variables = { url: 'https://github.com/Human-Connection/Human-Connection/pull/960' }
      })