How to use the got.mockReturnValueOnce function in got

To help you get started, we’ve selected a few got 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 hainproject / hain / app / main / plugins / hain-package-manager / __tests__ / search-client.spec.js View on Github external
pit('should reject if `got` has rejected', () => {
      mock_got.mockReturnValueOnce(Promise.resolve(null));

      return searchClient.findCompatiblePackages('fakeBackend', []).then(
        (ret) => {
          throw new Error('Promise should not be resolved');
        },
        (err) => {
          // done
        }
      );
    });
  });
github hainproject / hain / app / main / plugins / hain-commands / __tests__ / check-update.spec.js View on Github external
pit('should return latest version and url', () => {
    const latestVersion = '0.2.0';
    const downloadUrl = 'download-0.2.0';

    const githubAPIData = [
      {
        tag_name: `v${latestVersion}`,
        html_url: downloadUrl
      },
      {
        tag_name: 'v0.1.0',
        html_url: 'fake'
      }
    ];

    mock_got.mockReturnValueOnce(
      Promise.resolve({
        body: githubAPIData
      })
    );

    return checkForUpdate().then((res) => {
      expect(res).toEqual({
        version: latestVersion,
        url: downloadUrl
      });
    });
  });
});