How to use the @octokit/rest.mockImplementation function in @octokit/rest

To help you get started, we’ve selected a few @octokit/rest 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 algolia / shipjs / packages / shipjs / src / step / release / __tests__ / createGitHubRelease.spec.js View on Github external
config: {
    getTagName: () => 'v1.2.3',
    releases: { assetsToUpload, extractChangelog },
    updateChangelog: false,
  },
  dir: '.',
  dryRun: false,
});

const createRelease = jest.fn().mockImplementation(() => ({
  data: {
    upload_url: 'https://dummy/upload/url', // eslint-disable-line camelcase
  },
}));
const uploadReleaseAsset = jest.fn();
Octokit.mockImplementation(function() {
  this.repos = { createRelease, uploadReleaseAsset };
});

describe('createGitHubRelease', () => {
  beforeEach(() => {
    getRepoInfo.mockImplementation(() => ({
      owner: 'my',
      name: 'repo',
    }));
    fs.readFileSync = jest.fn();
    fs.statSync = jest.fn().mockImplementation(() => ({ size: 1024 }));
    mime.lookup.mockImplementation(() => 'application/zip');
    globby.mockImplementation(path => Promise.resolve([path]));
  });

  it('works without assets', async () => {