How to use the node-fetch.mock 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 Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / __tests__ / UpwardDevServerPlugin.spec.js View on Github external
devServer.after(app);
    const handler = app.use.mock.calls[0][0];
    handler();
    await plugin.middlewarePromise;

    const io = upward.middleware.mock.calls[0][2];

    io.networkFetch('http://example.com', { method: 'POST' });

    expect(fetch).toHaveBeenCalledWith(
        'http://example.com',
        expect.objectContaining({
            method: 'POST'
        })
    );
    expect(fetch.mock.calls[0][1]).not.toHaveProperty('agent');
});
github gnosis / verify-on-etherscan / __tests__ / integration.js View on Github external
.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));
  expect(fetchReturns).toMatchSnapshot('Fetch returns');

  expect(replaceCWD(alreadyVerified)).toMatchSnapshot('Already verified');

  const all = Object.keys(artifactsData).length;
  const unverifiedKeys = Object.keys(unverifiedContracts);
  const verified = all - unverifiedKeys.length;
  expect(verified).toEqual(2);
  expect(verified).toEqual(alreadyVerified.length);

  expect(unverifiedKeys).toMatchSnapshot('Unverified contracts');

  unverifiedKeys.forEach(key => {
    expect(replaceCWD(unverifiedContracts[key])).toMatchSnapshot(
      {
        bytecode: expect.any(String),
github gnosis / verify-on-etherscan / __tests__ / integration.js View on Github external
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));
  expect(fetchReturns).toMatchSnapshot('Fetch returns');

  expect(replaceCWD(alreadyVerified)).toMatchSnapshot('Already verified');

  const all = Object.keys(artifactsData).length;
  const unverifiedKeys = Object.keys(unverifiedContracts);
  const verified = all - unverifiedKeys.length;
  expect(verified).toEqual(2);
  expect(verified).toEqual(alreadyVerified.length);

  expect(unverifiedKeys).toMatchSnapshot('Unverified contracts');

  unverifiedKeys.forEach(key => {
    expect(replaceCWD(unverifiedContracts[key])).toMatchSnapshot(