Skip to content

Commit

Permalink
fix: is not a function in CatchAll listener (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed Apr 5, 2024
1 parent 5dc3a8b commit f212f5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Robot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Robot {
}

this.listen(isCatchAllMessage, options, async msg => {
await callback(msg.message)
await callback(msg)
})
}

Expand Down
27 changes: 23 additions & 4 deletions test/Robot_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
import path from 'node:path'
import { Robot, CatchAllMessage, EnterMessage, LeaveMessage, TextMessage, TopicMessage, User } from '../index.mjs'
import { Robot, CatchAllMessage, EnterMessage, LeaveMessage, TextMessage, TopicMessage, User, Response } from '../index.mjs'
import mockAdapter from './fixtures/MockAdapter.mjs'
describe('Robot', () => {
describe('#http', () => {
Expand Down Expand Up @@ -204,11 +204,30 @@ describe('Robot', () => {
it('sends a CatchAllMessage if no listener matches', async () => {
const testMessage = new TextMessage(user, 'message123')
robot.listeners = []
let actual = null
robot.catchAll(async (message) => {
assert.ok(message instanceof CatchAllMessage)
assert.deepEqual(message.message, testMessage)
actual = message
})
await robot.receive(testMessage)
assert.ok(actual.message instanceof CatchAllMessage)
assert.deepEqual(actual.message.message, testMessage)
})

it('calls the catch-all listener with a Response object', async () => {
const testMessage = new TextMessage(user, 'message123')

const listenerCallback = async () => {
assert.fail('Should not have called listener')
}
robot.hear(/^no-matches$/, listenerCallback)
let actual = null
robot.catchAll(async response => {
response.reply('caught by catchAll')
actual = response
})

await robot.receive(testMessage)
assert.ok(actual instanceof Response)
})

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

robot.catchAll(async response => {
assert.deepEqual(response.message, testMessage)
assert.deepEqual(response.message.message, testMessage)
})

await robot.receive(testMessage)
Expand Down

0 comments on commit f212f5d

Please sign in to comment.