首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Hubot - AssertionError -helper和chai测试hubot脚本时的测试

使用Hubot - AssertionError -helper和chai测试hubot脚本时的测试
EN

Stack Overflow用户
提问于 2019-05-07 17:18:27
回答 1查看 138关注 0票数 4

我正在为我的Hubot (充当Slack bot)编写一个简单的测试,以检查我的bot是否发送响应触发器的回复。我遵循了docs中显示的示例,但测试结果是AssertionError (详细信息如下),我不确定原因。任何建议都将不胜感激。

我假设问题与测试有关,而不是脚本(break-start.coffee),因为当我从Slack向机器人发送一条实际的消息来测试脚本时,我得到了正确的回复。

代码语言:javascript
复制
# 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')
代码语言:javascript
复制
# 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']
      ]
代码语言:javascript
复制
# 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"
      +  ]
       ]

顺便说一句,这里以前也有一个非常相似的question,但它没有得到回复。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-07 19:36:21

我认为这个问题是一个缩进错误。

传递给@room.user.say调用的是一个空函数作为promise解析,而不是expect块,因为这应该缩进到另一个级别。

这与房间中只有一条消息的结果相吻合,因为在执行异步@room.user.say()之前执行了expect调用:

代码语言:javascript
复制
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']
    ]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56019357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档