gpt4 book ai didi

debugging - 使用 hubot-test-helper 和 chai 测试 Hubot 脚本时出现 AssertionError

转载 作者:行者123 更新时间:2023-11-28 19:53:28 25 4
gpt4 key购买 nike

我正在为我的 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"
+ ]
]

顺便说一句,有一个极其相似的question之前在这里发布过,但没有得到答复。

最佳答案

我认为问题是缩进错误。

@room.user.say 调用被传递一个空函数作为 promise 解决方案而不是 expect block ,因为这应该缩进另一个级别。

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

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']
]

关于debugging - 使用 hubot-test-helper 和 chai 测试 Hubot 脚本时出现 AssertionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56019357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com