Skip to content
/ portend Public

A library for expecting events to be emitted

Notifications You must be signed in to change notification settings

nsand/portend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portend

Build Status Coverage Status

Portend is a utility for expecting a particular event to be emitted a specific number of times.

It can be useful for writing tests in which a known number of events are expected to be emitted, and the test must wait before proceeding.

Usage

Portend requires that it be called with an EventEmitter-like object (something with an on function) and an event name. By default, it will expect the event to be fired once, but this can be overridden with the third parameter.

Generic Scenario

const portend = require('portend');

// Wait for my.event to be emitted twice from the emitter
portend(emitter, 'my.event', 2).then(events => {
	// events will ['test', 'test 2']
});

emitter.emit('my.event', 'test');
emitter.emit('my.event', 'test 2');

Shortcuts

There are a few shortcuts for setting up the expected number of emits. once, twice, and thrice can be used to expect 1, 2 and 3 emits respectively.

const portend = require('portend');

// Wait for my.event to be emitted once
portend.once(emitter, 'my.event').then(events => {
	// events will be ['test']
});

emitter.emit('my.event', 'test');

About

A library for expecting events to be emitted

Resources

Stars

Watchers

Forks

Packages

No packages published