Skip to content

Commit f212f5d

Browse files
authored
fix: is not a function in CatchAll listener (#1720)
1 parent 5dc3a8b commit f212f5d

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/Robot.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Robot {
229229
}
230230

231231
this.listen(isCatchAllMessage, options, async msg => {
232-
await callback(msg.message)
232+
await callback(msg)
233233
})
234234
}
235235

test/Robot_test.mjs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { describe, it, beforeEach, afterEach } from 'node:test'
44
import assert from 'node:assert/strict'
55
import path from 'node:path'
6-
import { Robot, CatchAllMessage, EnterMessage, LeaveMessage, TextMessage, TopicMessage, User } from '../index.mjs'
6+
import { Robot, CatchAllMessage, EnterMessage, LeaveMessage, TextMessage, TopicMessage, User, Response } from '../index.mjs'
77
import mockAdapter from './fixtures/MockAdapter.mjs'
88
describe('Robot', () => {
99
describe('#http', () => {
@@ -204,11 +204,30 @@ describe('Robot', () => {
204204
it('sends a CatchAllMessage if no listener matches', async () => {
205205
const testMessage = new TextMessage(user, 'message123')
206206
robot.listeners = []
207+
let actual = null
207208
robot.catchAll(async (message) => {
208-
assert.ok(message instanceof CatchAllMessage)
209-
assert.deepEqual(message.message, testMessage)
209+
actual = message
210210
})
211211
await robot.receive(testMessage)
212+
assert.ok(actual.message instanceof CatchAllMessage)
213+
assert.deepEqual(actual.message.message, testMessage)
214+
})
215+
216+
it('calls the catch-all listener with a Response object', async () => {
217+
const testMessage = new TextMessage(user, 'message123')
218+
219+
const listenerCallback = async () => {
220+
assert.fail('Should not have called listener')
221+
}
222+
robot.hear(/^no-matches$/, listenerCallback)
223+
let actual = null
224+
robot.catchAll(async response => {
225+
response.reply('caught by catchAll')
226+
actual = response
227+
})
228+
229+
await robot.receive(testMessage)
230+
assert.ok(actual instanceof Response)
212231
})
213232

214233
it('does not trigger a CatchAllMessage if a listener matches', async () => {
@@ -572,7 +591,7 @@ describe('Robot', () => {
572591
robot.hear(/^no-matches$/, listenerCallback)
573592

574593
robot.catchAll(async response => {
575-
assert.deepEqual(response.message, testMessage)
594+
assert.deepEqual(response.message.message, testMessage)
576595
})
577596

578597
await robot.receive(testMessage)

0 commit comments

Comments
 (0)