Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest returns Error: secretOrPrivateKey must have a value after upgrade probot #1469

Closed
LukeGuanY opened this issue Jan 28, 2021 · 1 comment

Comments

@LukeGuanY
Copy link

LukeGuanY commented Jan 28, 2021

Bug Report

Current Behavior
I update the probot to 11.0.5, and object { Application } = require("probot") is deprecated. I found the equivalent one { probot }.

When I run my unit test, it always returns "Error: secretOrPrivateKey must have a value". I have already mock-up the method I am going to test, how can I fix this error? Thank you.

Before I initialized the app from Application obj, it didn't require me to provide any credentials.

const { Probot } = require("probot");  //Used to be const { Application } = require("probot");
const plugin = require("..");
const pullRequestOpenedPayload = require("./fixtures/pull_request.opened.json");

describe("Size", () => {
  let probot;
  let octokit;

  beforeEach(async () => {
    probot = new Probot(); //Used to be  app = new Application()
    plugin(probot);

    octokit = {
      issues: {
        addLabels: jest.fn().mockReturnValue(Promise.resolve({})),
      },
    };
    probot.auth = () => Promise.resolve(octokit);
  });

  test("creates a label when a pull request is opened", async () => {
    await probot.receive({
      name: "pull_request.opened",
      payload: pullRequestOpenedPayload,
    });
    expect(octokit.issues.addLabels).toHaveBeenCalled();
  });
});

Environment

  • Probot version(s): [e.g. 11.0.5]
@gr2m
Copy link
Contributor

gr2m commented Jan 31, 2021

I would recommend against mocking the octokit instance. If a future version renames the octokit.issues.addLabels method, your tests will still pass, but it will fail in production. I would mock the http requests instead, see https://probot.github.io/docs/testing/

I think new Probot() won't work, try new Probot({ githubToken: "test" }) instead

Probot
GitHub Apps to automate and improve your workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants