Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: is not a function in CatchAll listener #1725

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading