简体   繁体   English

使用Hubot-Test-Helper和Chai测试Hubot脚本时出现AssertionError

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

I'm writing a simple test for my Hubot (which acts as a Slack bot) to check that my bot sends a reply in response to triggers. 我正在为Hubot(充当Slack机器人)编写一个简单的测试,以检查我的机器人是否发送了响应触发器的回复。 I've followed the example shown in the docs , but test results in an AssertionError (details below) and I'm not sure why. 我遵循了docs中显示的示例,但是测试导致出现AssertionError (下面的详细信息),但我不确定为什么。 Any advice would be greatly appreciated. 任何建议将不胜感激。

I assume the issue has to do with the test, not the script ( break-start.coffee ), since I got the correct reply when I tested the script by sending an actual message to the bot from Slack. 我认为问题与测试有关,而不是脚本( 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"
      +  ]
       ]

By the way, there was an extremely similar question posted here before but it went unanswered. 顺便说一句,之前有一个非常类似的问题在这里发布,但是没有得到回答。

I think the problem is an indentation error. 我认为问题是缩进错误。

The @room.user.say call is being passed an empty function as a promise resolution rather than the expect block, as this should be indented another level. 正在向@room.user.say调用传递一个空函数作为承诺解决方案,而不是@room.user.say块,因为应该将其缩进另一个级别。

That fits with the result that only one message is in the room, as the expect call got executed before the async @room.user.say() got executed: 这与只有一条消息在房间中的结果@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.

相关问题 从Microsoft测试管理器运行时如何在Visual Studio中调试硒测试脚本(C#) - How to debug selenium test script (C#) in Visual studio while running from Microsoft test manager 如何在测试AJAX应用程序时测试断开连接? - How to test a disconnection when testing an AJAX application? 如何使用 GDB 创建测试脚本 - How can I create a testing script with GDB 为什么此代码会引发 AssertionError? - Why is this code raising an AssertionError? 内部错误:org.jetbrains.concurrency.MessageError:远程上的助手脚本失败:_jb_debug_helper未定义 - Internal error: org.jetbrains.concurrency.MessageError: Helper script failed on remote: _jb_debug_helper is not defined 无法在测试香草机上测试视觉c exe - Testing a visual c exe on a test vanilla machine don't start python 3.4 pycharm调试器中的AssertionError - python 3.4 AssertionError in pycharm debugger PHP脚本仅在Safari中不起作用(仅在线-在本地进行测试) - Php script not working in Safari only (online only - it works locally for testing) 在 Testcafe 中开发测试时保持浏览器打开 - Keep browser open while developing a test in Testcafe 如何使用 ProGuard 进行混淆但在测试时保持名称可读? - How to obfuscate with ProGuard but keep names readable while testing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM