Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @charisma-ai/event-emitter-tester with all npm packages installed. Try it out:

var eventEmitterTester = require("@charisma-ai/event-emitter-tester")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@charisma-ai/event-emitter-tester v0.0.3

Tester for emitters with on/off interface

Event Emitter Tester

A utility to make testing event emitters simpler.

Usage

yarn add @charisma-ai/event-emitter-tester
import EventEmitterTester from "@charisma-ai/event-emitter-tester";

class MyTester extends EventEmitterTester {
  constructor(emitter, options = {}) {
    super(emitter, options);
  }

  reply(text: string): MyTester {
    this.addToQueue(() => {
      // do your event here...
    });
    return this;
  }

  awaitMessage(callback: (message: string) => void): MyTester {
    this.awaitEvent("message", callback);
    return this;
  }
}

async function run() {
  const tester = new MyTester(emitter, { timeout: 5000 });
  await tester
    .reply("Hello!")
    .reply("How are you?")
    .awaitMessage(message => expect(message).toEqual("Great thanks"))
    .reply("Ideal!")
    .awaitMessage(message => expect(message).toEqual("Indeed."))
    .run();
  console.log("Complete!");
}
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free