Provides a mock robot context to enable unit testing of hubot scripts
npm install mock-hubot-robot```
npm install mock-hubot-robot
Assuming a file in a test folder off the root of your hubot source
Using Mocha and Chai
some-test-file-name.js`js
require('coffee-script')
require('coffee-script/register')
var robotCtx = require('../')(),
testscript = require('./testscript.coffee'),
expect = require('chai').expect
describe('Testing that my robot hears correctly',function() {
before(function(done) {
//This is what binds the robot context into your script.
testscript(robotCtx)
done()
})
it('hears phrase "who\'s here"',function(done) {
//Execute your phrase against all of the robot.hear bindings your script has made
robotCtx.ExecHear("who's here?",function(matched) {
expect(matched).to.be.true
done()
})
})
})
`
testscript.coffee`coffee`
module.exports = (robot) ->
robot.hear /who's here/, (res) ->
console.log("called")
Output
`
Testing that my robot hears correctly
✓ hears phrase "who's here"
1 passing (11ms)
``