Skip to content

Instantly share code, notes, and snippets.

@selfcontained
Created September 15, 2017 19:10
Show Gist options
  • Save selfcontained/a5fb22cc2a7a9dd787c9d09ba68ae3f0 to your computer and use it in GitHub Desktop.
Save selfcontained/a5fb22cc2a7a9dd787c9d09ba68ae3f0 to your computer and use it in GitHub Desktop.
const slapp = require('slapp')
slapp.message('^(hi|hello|hey).*', ['direct_mention', 'direct_message'], helloHandler)
// Pull slapp message handler into a function you can export and test
function helloHandler (msg, text, greeting) {
msg.say(`${greeting}, how are you?`)
}
// write a test for just the handler
describe('hello handler', () => {
it('should reply w/ greeting', () => {
let msg = {}
let sayStub = sinon.stub(msg, 'say')
helloHandler(msg, '', 'hello')
assert(sayStub.calledWith('hello, how are you?'))
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment