【问题标题】:Hubot Unit Testing Not Receiving ResponseHubot 单元测试未收到响应
【发布时间】:2018-07-04 23:59:04
【问题描述】:

我正在尝试为我的 hubot 代码设置一个简单的单元测试,但我没有收到回复。我已将其简化为:

test.coffee:

Helper = require('hubot-test-helper')
chai = require 'chai'
expect = chai.expect
helper = new Helper('../hubot-scripts/something.coffee')

describe 'PING', ->
    beforeEach ->
        @room = helper.createRoom()
    afterEach ->
        @room.destroy

    it 'should PONG', ->
        @room.user.say 'alice', '@hubot PING'
        expect(@room.messages).to.eql [
            ['alice', '@hubot PING'],
            ['hubot', 'PONG']
        ]

还有一些东西。咖啡:

module.exports = (robot) ->
    robot.response /PING$/i, (msg) ->
        msg.send 'PONG'

当我运行测试时,我收到以下断言错误:

  AssertionError: expected [ [ 'alice', '@hubot PING' ] ] to deeply equal [ Array(2) ]
  + expected - actual

     [
       "alice"
       "@hubot PING"
     ]
  +  [
  +    "hubot"
  +    "PONG"
  +  ]
   ]

意思是我根本没有得到回复。我尝试将@hubot 更改为hubot(这没关系)。我还验证了它正在找到我的 something.coffee,因为当我将该路径更改为不正确的路径时,我收到了一个错误。

我正在关注https://hubot.github.com/docs/scripting/底部的例子

感谢您的帮助!

【问题讨论】:

    标签: coffeescript mocha.js chai hubot


    【解决方案1】:

    对于访问此主题的任何人,当我遇到同样的问题时,我发布了 question。 简而言之,问题是缩进——以expect 开头的行在@room.user.say 执行之前被调用。详情请查看我的链接。

    【讨论】:

      【解决方案2】:

      我不知道为什么,但是将 @room.user.say 移到 before 块中可以做到这一点。

      【讨论】:

      • 你能发布你的代码吗?我遇到了同样的问题,但无法理解您的指示。我已经创建了一个 before -> 并将我的整个测试放在那里。
      猜你喜欢
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 2011-04-12
      相关资源
      最近更新 更多