probot.receive in tests throws an error

Created on 7 Jul 2019  ·  3Comments  ·  Source: probot/probot

Bug Report

The default tests for the ts-basic application template throws an error at probot.receive

Current Behavior
This test throws a typeError that seems to stem from come from @octokit

import nock from 'nock'
// Requiring our app implementation
import myProbotApp from '../src'
import { Probot } from 'probot'
// Requiring our fixtures
import payload from './fixtures/issues.opened.json'
const issueCreatedBody = { body: 'Thanks for opening this issue!' }

nock.disableNetConnect()

describe('My Probot app', () => {
  let probot: any

  beforeEach(() => {
    probot = new Probot({ id: 123, cert: 'test' })
    // Load our app into probot
    const app = probot.load(myProbotApp)

    // just return a test token
    app.app = () => 'test'
  })

  test('creates a passing check', async () => {
    // Test that we correctly return a test token
    nock('https://api.github.com')
      .post('/app/installations/2/access_tokens')
      .reply(200, { token: 'test' })

    // Test that a commented is posted
    nock('https://api.github.com')
      .post('/repos/hiimbex/testing-things/issues/1/comments', (body: any) => {
        expect(body).toMatchObject(issueCreatedBody)
        return true
      })
      .reply(200)

    // Recieve a webhook event
    await probot.receive({ name: 'issues', payload })
  })
})

However, on npm run test we get an error:

  ● My Probot app › creates a passing check

    TypeError: this.app.getSignedJsonWebToken is not a function

      39 | 
      40 |     // Recieve a webhook event
    > 41 |     await probot.receive({ name: 'issues', payload })
         |                  ^
      42 |   })
      43 | })
      44 | 

Expected behavior/code
Test Passes

Environment

  • Probot version(s): 9.2.15
  • Node/npm version: 6.10.0
  • OS: Debian 9.8

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

bug 🐞

All 3 comments

Issue-Label Bot is automatically applying the label bug 🐞 to this issue, with a confidence of 0.97. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

Oops, the test itself was broken because of this line app.app = () => 'test'. This was, however, a default test that came with create-probot-app. I'll open up an issue over there.

Fixed by removing that line and changing probot = new Probot({ id: 123, cert: 'test' }) to probot = new Probot({ id: 123, githubToken: 'test' }).

Was this page helpful?
0 / 5 - 0 ratings