-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
robot.http has no effect in tests #19
Comments
Hmm, I'll investigate 💫 |
Hi @pchaigno the problem is on two fronts. I ran the tests as below: Helper = require('hubot-test-helper')
helper = new Helper('../scripts/s1.coffee')
co = require('co')
expect = require('chai').expect
# test ping
describe 'http', ->
beforeEach ->
@room = helper.createRoom(httpd: false)
# Test case
context 'user posts link', ->
beforeEach ->
co =>
yield @room.user.say 'user1', 'http://google.com'
# response
it 'does not expect deplayed callback', ->
console.log @room.messages
expect(@room.messages).to.eql [
['user1', 'http://google.com']
['hubot', 'ok1: http://google.com']
]
# response
it 'expects deplayed callback from ok2', ->
console.log @room.messages
expect(@room.messages).to.eql [
['user1', 'http://google.com']
['hubot', 'ok1: http://google.com']
['hubot', 'ok2: http://google.com']
]
Anyways, the first test
Perhaps the delayed action from
I'll leave this to @mtsmfm |
I don't think that using http://mochajs.org/#working-with-promises In this case, the Promise is returned by the The real problem is that there is no Promise associated with the http call, which is asynchronous. I doubt there is a way to force the test to wait for the result of the HTTP call. In this case I'd use a mocking library to stub out the http call. (In other words, your HTTP call is probably being triggered, but the test finishes before the callback is executed.) |
@mdelagrange I agree, but there's no simple way to obtain the promise from the bot script. However since it is promise based, just like real-life interaction, the tester shall expect some time delay from the bot, although it cannot called directly (there's no handle as mentioned) when the promise resolves. Adding that manual, expected time delay solves it, and the Below is a snippet slightly modified from my earlier version that works. Helper = require('hubot-test-helper')
helper = new Helper('../scripts/s1.coffee')
co = require('co')
expect = require('chai').expect
# test ping
describe 'http', ->
beforeEach ->
@room = helper.createRoom(httpd: false)
# Test case
context 'user posts link', ->
beforeEach ->
co =>
yield @room.user.say 'user1', 'http://google.com'
# delay one second here
yield new Promise((resolve, reject) ->
setTimeout(resolve, 1000);
)
# response
it 'expects deplayed callback from ok2', ->
console.log @room.messages
expect(@room.messages).to.eql [
['user1', 'http://google.com']
['hubot', 'ok1: http://google.com']
['hubot', 'ok2: http://google.com']
] passes the test: |
@mtsmfm in the light of this issue, can we implement a feature where sending a message will emit an event 'message sent', and so when the room handles the event by expecting a message; then when it receives the message it resolves and returns a promise? This is more reliable than waiting an arbitrary time - I found out that during busy times on Travis it could take up to 5 seconds for a room to receive a message. |
Sorry for late response 😓
Thanks very useful advice 👍 |
add issue #19 manual delay solution to README
close via #25 |
See https://github.com/mtsmfm/hubot-test-helper#manual-delay and mtsmfm/hubot-test-helper#19 for background on the forced delay in tests
See https://github.com/mtsmfm/hubot-test-helper#manual-delay and mtsmfm/hubot-test-helper#19 for background on the forced delay in tests
See https://github.com/mtsmfm/hubot-test-helper#manual-delay and mtsmfm/hubot-test-helper#19 for background on the forced delay in tests
So, the best solution still is to add a manual delay? |
It looks like there is an issue with
robot.http
when usinghubot-test-helper
. The following script works fine with a Hubot shell but the associated test does not seem to trigger any HTTP request.Script:
Test:
The text was updated successfully, but these errors were encountered: