@charisma-ai/event-emitter-tester
v0.0.3
Published
Tester for emitters with on/off interface
Downloads
25
Keywords
Readme
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!");
}