Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Should emit the change data to all active listeners', () => {
const emitter = new EventEmitter();
const listener1 = function() {};
const listener2 = function(data) {
console.error(data);
};
spyOn(console, 'error');
expect(emitter.listeners.length).toEqual(0);
const listener = emitter.on(listener1);
const listenerTwo = emitter.on(listener2);
expect(emitter.listeners.length).toEqual(2);
expect(emitter.listeners[0]).toEqual(listener1);
listener();
it('Should do nothing if removing same callback twice/or more', () => {
const emitter = new EventEmitter();
const listener1 = function() {};
expect(emitter.listeners.length).toEqual(0);
const listener = emitter.on(listener1);
expect(emitter.listeners.length).toEqual(1);
expect(emitter.listeners[0]).toEqual(listener1);
listener();
listener();
listener();
expect(emitter.listeners.length).toEqual(0);
});