簡體   English   中英

使用Hubot-Test-Helper和Chai測試Hubot腳本時出現AssertionError

[英]AssertionError while testing Hubot script with hubot-test-helper and chai

我正在為Hubot(充當Slack機器人)編寫一個簡單的測試,以檢查我的機器人是否發送了響應觸發器的回復。 我遵循了docs中顯示的示例,但是測試導致出現AssertionError (下面的詳細信息),但我不確定為什么。 任何建議將不勝感激。

我認為問題與測試有關,而不是腳本( break-start.coffee ),因為通過從Slack向機器人發送實際消息來測試腳本時,我得到了正確的答復。

# break-start.coffee
# Basically, the bot says "Later alligator" to any user going on lunch break.

module.exports = (robot) ->
  robot.respond /off to lunch/i, (res) ->
    res.reply('Later alligator')
# break-start-test.coffee

'use strict'

Helper = require('hubot-test-helper')
helper = new Helper('../scripts/break-start.coffee')
request = require('request')
expect = require('chai').expect

describe 'bot responds to user message', ->
  beforeEach ->
    # Set up the room before running the test.
    @room = helper.createRoom()

  afterEach ->
    # Tear it down after the test to free up the listener.
    @room.destroy()

  it 'responds to users who are off to lunch', ->
    @room.user.say('bob', '@hubot Off to lunch').then =>
    expect(@room.messages).to.eql [
        ['bob', '@hubot Off to lunch']
        ['hubot', '@bob Later alligator']
      ]

# The error message

AssertionError: expected [ [ 'bob', '@hubot Off to lunch' ] ] to deeply equal [ Array(2) ]
      + expected - actual

         [
           "bob"
           "@hubot Off to lunch"
         ]
      +  [
      +    "hubot"
      +    "@bob Later alligator"
      +  ]
       ]

順便說一句,之前有一個非常類似的問題在這里發布,但是沒有得到回答。

我認為問題是縮進錯誤。

正在向@room.user.say調用傳遞一個空函數作為承諾解決方案,而不是@room.user.say塊,因為應該將其縮進另一個級別。

這與只有一條消息在房間中的結果@room.user.say() ,因為在執行異步@room.user.say()之前執行了expect調用:

it 'responds to users who are off to lunch', ->
  @room.user.say('bob', '@hubot Off to lunch').then =>
    expect(@room.messages).to.eql [
      ['bob', '@hubot Off to lunch']
      ['hubot', '@bob Later alligator']
    ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM