I'm trying to set up a simple unit test for my hubot code and I am not receiving responses back. I have simplified this down to:
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']
]
and something.coffee:
module.exports = (robot) ->
robot.response /PING$/i, (msg) ->
msg.send 'PONG'
When I run my tests, I get an assertion error of:
AssertionError: expected [ [ 'alice', '@hubot PING' ] ] to deeply equal [ Array(2) ]
+ expected - actual
[
"alice"
"@hubot PING"
]
+ [
+ "hubot"
+ "PONG"
+ ]
]
Meaning I am not getting a response back at all. I have tried changing @hubot to hubot (which shouldn't matter). I also verified that it is finding my something.coffee, as when I changed that path to an incorrect one I received an error about that.
I am following the example at bottom of https://hubot.github.com/docs/scripting/
Thanks for the help!
For anyone who reached this thread, I posted a question when I experienced the same issue.
In short, the issue was indentation - the line beginning with expect
was being called before the @room.user.say
was executed. Please see my link for more details.
I don't know why, but moving the @room.user.say into a before block made this work.
来源:https://stackoverflow.com/questions/48447909/hubot-unit-testing-not-receiving-response