我正在尝试为我的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']
]和something.coffee:
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/底部的示例
谢谢你的帮助!
发布于 2019-05-08 08:43:22
对于任何读到这个帖子的人,当我遇到同样的问题时,我发布了一个question。简而言之,问题是缩进-在执行@room.user.say之前,以expect开头的行被调用。请查看我的链接了解更多详细信息。
发布于 2018-01-26 02:11:24
我不知道为什么,但是将@room.user.say移到了一个before块中,这样就可以工作了。
https://stackoverflow.com/questions/48447909
复制相似问题