@charisma-ai/event-emitter-tester
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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!");
}

Dependents (0)

Package Sidebar

Install

npm i @charisma-ai/event-emitter-tester

Weekly Downloads

4

Version

0.0.3

License

MIT

Unpacked Size

6.89 kB

Total Files

10

Last publish

Collaborators

  • radu-dum
  • samuelbeard
  • szabinakov
  • john-a-j
  • benhjames