npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

botkit-mock

v0.7.5-4

Published

Write tests for botkit.

Downloads

223

Readme

Botkit-Mock - Write tests for Botkit.

npm Build Status

Setup

  1. npm install --save botkit-mock
  2. Require botkit-mock in your test: const Botmock = require('botkit-mock');
  3. Require your controller in your test: const fileBeingTested = require("./indexController")
  4. Follow test case examples seen here

Basic Usage

Testing Controllers

Let's say you have a controller that looks something like this:

module.exports = function(controller) {
    // simple answer
    controller.hears(['help'], 'direct_message', function (bot, message) {
        bot.reply(message, 'help message');
    });
}

To use botkit-mock, you can test your controller like below:

const Botmock = require('botkit-mock');
const yourController = require("./yourController");

describe("controller tests",()=>{
    beforeEach(()=>{
        this.controller = Botmock({});
        // type can be ‘slack’, facebook’, or null
        this.bot = this.controller.spawn({type: 'slack'});
        yourController(this.controller);
    });
});

In your it statement, use the bot.usersInput method to define the conversation.

it('should return `help message` if user types `help`', () => {
    return this.bot.usersInput(
        [
            {
                user: 'someUserId',
                channel: 'someChannel',
                messages: [
                    {
                        text: 'help', isAssertion: true
                    }
                ]
            }
        ]
    ).then((message) => {
        // In message, we receive a full object that includes params:
        // {
        //    user: 'someUserId',
        //    channel: 'someChannel',
        //    text: 'help message',
        // }
        return assert.equal(message.text, 'help message');
    })
});

Advanced Usage

botExtender - allows developers to extend the bot and add custom functions to the bot. This overrides functionality in BotmockWorker.js.

To use this, define botExtender in your beforeEach. It accepts three parameters (bot, botkit, config), which are passed in from Botmock.js and BotmockWorker.js. Pass botExtender to your .spawn() and you will have access to your custom functions in the it.

beforeEach(()=>{
        function botExtender(bot, botkit, config){
            bot.customReply = function(message, text){
                bot.reply(message, 'Something new...' + text)
            }
        }
        this.bot = this.controller.spawn({type: 'slack', botExtender: botExtender});
    });

usersInput options

  1. user user slackId (required) (string)
  2. channel is a channel where user sends messages (required) (string)
  3. type specify botkit message type. ie direct_message, message_received, interactive_message_callback. (defaults to direct_message) (string)
  4. messages (array) that includes:
    • isAssertion indicates which conversation response array to return in .then() in multi-user testing. (required) (boolean)
    • deep indicates the index of the conversation response to return in .then(). 0 (default) is the last response, 1 is the second-to-last, etc.. (integer)
    • timeout set timeout for message in milliseconds (integer)
    • waitBefore alias for timeout, indicates how many milliseconds to wait before sending the message to the bot (integer)
    • waitAfter indicates how many milliseconds to wait for the bot response, useful for long-running commands (integer)
    • text the message's text (string)
    • channel indicates the channel the message was sent in. This overrides the channel defined in usersInput for this current message. (string)
    • ...any other fields you may be testing for including attachments, callback_id, etc...

Contributing

botkit-mock currently (and will always) support all of Botkit's core functionality by default. We also support extended Slack and Facebook functionality.

To add functionality to botkit-mock, you can create platform-specific functions like seen in FacebookBotWorker. If you add functionality to support something we don't, please make a PR.

Examples

Built by the team at https://www.gratify.chat.

Like botkit-mock? Donate BTC to our team: 1KwpqzTvpLWiUST2V5wmPiT3twwc1pZ9tP

Change Log