Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@charisma-ai/event-emitter-tester

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

Keywords

none

Install

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

DownloadsWeekly Downloads

34

Version

0.0.3

License

MIT

Unpacked Size

6.89 kB

Total Files

10

Last publish

Collaborators

  • avatar
  • avatar