|
|
@@ -6,1110 +6,1112 @@
|
|
|
import EmitterMixin from 'ckeditor5/utils/emittermixin.js';
|
|
|
import EventInfo from 'ckeditor5/utils/eventinfo.js';
|
|
|
|
|
|
-let emitter, listener;
|
|
|
+describe( 'EmitterMixin', () => {
|
|
|
+ let emitter, listener;
|
|
|
|
|
|
-beforeEach( refreshEmitter );
|
|
|
+ beforeEach( refreshEmitter );
|
|
|
|
|
|
-describe( 'fire', () => {
|
|
|
- it( 'should execute callbacks in the right order without priority', () => {
|
|
|
- let spy1 = sinon.spy().named( 1 );
|
|
|
- let spy2 = sinon.spy().named( 2 );
|
|
|
- let spy3 = sinon.spy().named( 3 );
|
|
|
+ describe( 'fire', () => {
|
|
|
+ it( 'should execute callbacks in the right order without priority', () => {
|
|
|
+ let spy1 = sinon.spy().named( 1 );
|
|
|
+ let spy2 = sinon.spy().named( 2 );
|
|
|
+ let spy3 = sinon.spy().named( 3 );
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
- emitter.on( 'test', spy3 );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy3 );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- sinon.assert.callOrder( spy1, spy2, spy3 );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should execute callbacks in the right order with priority defined', () => {
|
|
|
- let spy1 = sinon.spy().named( 1 );
|
|
|
- let spy2 = sinon.spy().named( 2 );
|
|
|
- let spy3 = sinon.spy().named( 3 );
|
|
|
- let spy4 = sinon.spy().named( 4 );
|
|
|
- let spy5 = sinon.spy().named( 5 );
|
|
|
-
|
|
|
- emitter.on( 'test', spy2, { priority: 'high' } );
|
|
|
- emitter.on( 'test', spy3 ); // Defaults to 'normal'.
|
|
|
- emitter.on( 'test', spy4, { priority: 'low' } );
|
|
|
- emitter.on( 'test', spy1, { priority: 'highest' } );
|
|
|
- emitter.on( 'test', spy5, { priority: 'lowest' } );
|
|
|
+ sinon.assert.callOrder( spy1, spy2, spy3 );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ it( 'should execute callbacks in the right order with priority defined', () => {
|
|
|
+ let spy1 = sinon.spy().named( 1 );
|
|
|
+ let spy2 = sinon.spy().named( 2 );
|
|
|
+ let spy3 = sinon.spy().named( 3 );
|
|
|
+ let spy4 = sinon.spy().named( 4 );
|
|
|
+ let spy5 = sinon.spy().named( 5 );
|
|
|
|
|
|
- sinon.assert.callOrder( spy1, spy2, spy3, spy4, spy5 );
|
|
|
- } );
|
|
|
+ emitter.on( 'test', spy2, { priority: 'high' } );
|
|
|
+ emitter.on( 'test', spy3 ); // Defaults to 'normal'.
|
|
|
+ emitter.on( 'test', spy4, { priority: 'low' } );
|
|
|
+ emitter.on( 'test', spy1, { priority: 'highest' } );
|
|
|
+ emitter.on( 'test', spy5, { priority: 'lowest' } );
|
|
|
|
|
|
- it( 'should pass arguments to callbacks', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
+ sinon.assert.callOrder( spy1, spy2, spy3, spy4, spy5 );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'test', 1, 'b', true );
|
|
|
+ it( 'should pass arguments to callbacks', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- sinon.assert.calledWithExactly( spy1, sinon.match.instanceOf( EventInfo ), 1, 'b', true );
|
|
|
- sinon.assert.calledWithExactly( spy2, sinon.match.instanceOf( EventInfo ), 1, 'b', true );
|
|
|
- } );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
|
|
|
- it( 'should pass proper context to callbacks', () => {
|
|
|
- let ctx1 = {};
|
|
|
- let ctx2 = {};
|
|
|
+ emitter.fire( 'test', 1, 'b', true );
|
|
|
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
- let spy3 = sinon.spy();
|
|
|
+ sinon.assert.calledWithExactly( spy1, sinon.match.instanceOf( EventInfo ), 1, 'b', true );
|
|
|
+ sinon.assert.calledWithExactly( spy2, sinon.match.instanceOf( EventInfo ), 1, 'b', true );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.on( 'test', spy1, { context: ctx1 } );
|
|
|
- emitter.on( 'test', spy2, { context: ctx2 } );
|
|
|
- emitter.on( 'test', spy3 );
|
|
|
+ it( 'should pass proper context to callbacks', () => {
|
|
|
+ let ctx1 = {};
|
|
|
+ let ctx2 = {};
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
- sinon.assert.calledOn( spy1, ctx1 );
|
|
|
- sinon.assert.calledOn( spy2, ctx2 );
|
|
|
- sinon.assert.calledOn( spy3, emitter );
|
|
|
- } );
|
|
|
+ emitter.on( 'test', spy1, { context: ctx1 } );
|
|
|
+ emitter.on( 'test', spy2, { context: ctx2 } );
|
|
|
+ emitter.on( 'test', spy3 );
|
|
|
|
|
|
- it( 'should fire the right event', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.on( '1', spy1 );
|
|
|
- emitter.on( '2', spy2 );
|
|
|
+ sinon.assert.calledOn( spy1, ctx1 );
|
|
|
+ sinon.assert.calledOn( spy2, ctx2 );
|
|
|
+ sinon.assert.calledOn( spy3, emitter );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( '2' );
|
|
|
+ it( 'should fire the right event', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- sinon.assert.notCalled( spy1 );
|
|
|
- sinon.assert.called( spy2 );
|
|
|
- } );
|
|
|
+ emitter.on( '1', spy1 );
|
|
|
+ emitter.on( '2', spy2 );
|
|
|
|
|
|
- it( 'should execute callbacks many times', () => {
|
|
|
- let spy = sinon.spy();
|
|
|
+ emitter.fire( '2' );
|
|
|
|
|
|
- emitter.on( 'test', spy );
|
|
|
+ sinon.assert.notCalled( spy1 );
|
|
|
+ sinon.assert.called( spy2 );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
- emitter.fire( 'test' );
|
|
|
- emitter.fire( 'test' );
|
|
|
+ it( 'should execute callbacks many times', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
- sinon.assert.calledThrice( spy );
|
|
|
- } );
|
|
|
+ emitter.on( 'test', spy );
|
|
|
|
|
|
- it( 'should do nothing for a non listened event', () => {
|
|
|
- emitter.fire( 'test' );
|
|
|
- } );
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- it( 'should accept the same callback many times', () => {
|
|
|
- let spy = sinon.spy();
|
|
|
+ sinon.assert.calledThrice( spy );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.on( 'test', spy );
|
|
|
- emitter.on( 'test', spy );
|
|
|
- emitter.on( 'test', spy );
|
|
|
+ it( 'should do nothing for a non listened event', () => {
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ it( 'should accept the same callback many times', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
- sinon.assert.calledThrice( spy );
|
|
|
- } );
|
|
|
+ emitter.on( 'test', spy );
|
|
|
+ emitter.on( 'test', spy );
|
|
|
+ emitter.on( 'test', spy );
|
|
|
|
|
|
- it( 'should not fire callbacks for an event that were added while firing that event', () => {
|
|
|
- let spy = sinon.spy();
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.on( 'test', () => {
|
|
|
- emitter.on( 'test', spy );
|
|
|
+ sinon.assert.calledThrice( spy );
|
|
|
} );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ it( 'should not fire callbacks for an event that were added while firing that event', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
- sinon.assert.notCalled( spy );
|
|
|
- } );
|
|
|
+ emitter.on( 'test', () => {
|
|
|
+ emitter.on( 'test', spy );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should correctly fire callbacks for namespaced events', () => {
|
|
|
- let spyFoo = sinon.spy();
|
|
|
- let spyBar = sinon.spy();
|
|
|
- let spyAbc = sinon.spy();
|
|
|
- let spyFoo2 = sinon.spy();
|
|
|
-
|
|
|
- // Mess up with callbacks order to check whether they are called in adding order.
|
|
|
- emitter.on( 'foo', spyFoo );
|
|
|
- emitter.on( 'foo:bar:abc', spyAbc );
|
|
|
- emitter.on( 'foo:bar', spyBar );
|
|
|
-
|
|
|
- // This tests whether generic callbacks are also added to specific callbacks lists.
|
|
|
- emitter.on( 'foo', spyFoo2 );
|
|
|
-
|
|
|
- // All four callbacks should be fired.
|
|
|
- emitter.fire( 'foo:bar:abc' );
|
|
|
-
|
|
|
- sinon.assert.callOrder( spyFoo, spyAbc, spyBar, spyFoo2 );
|
|
|
- sinon.assert.calledOnce( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyAbc );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- sinon.assert.calledOnce( spyFoo2 );
|
|
|
-
|
|
|
- // Only callbacks for foo and foo:bar event should be called.
|
|
|
- emitter.fire( 'foo:bar' );
|
|
|
-
|
|
|
- sinon.assert.calledOnce( spyAbc );
|
|
|
- sinon.assert.calledTwice( spyFoo );
|
|
|
- sinon.assert.calledTwice( spyBar );
|
|
|
- sinon.assert.calledTwice( spyFoo2 );
|
|
|
-
|
|
|
- // Only callback for foo should be called as foo:abc has not been registered.
|
|
|
- // Still, foo is a valid, existing namespace.
|
|
|
- emitter.fire( 'foo:abc' );
|
|
|
-
|
|
|
- sinon.assert.calledOnce( spyAbc );
|
|
|
- sinon.assert.calledTwice( spyBar );
|
|
|
- sinon.assert.calledThrice( spyFoo );
|
|
|
- sinon.assert.calledThrice( spyFoo2 );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
-describe( 'on', () => {
|
|
|
- it( 'should stop()', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
- let spy3 = sinon.spy( ( event ) => {
|
|
|
- event.stop();
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
} );
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
- emitter.on( 'test', spy3 );
|
|
|
- emitter.on( 'test', sinon.stub().throws() );
|
|
|
- emitter.on( 'test', sinon.stub().throws() );
|
|
|
+ it( 'should correctly fire callbacks for namespaced events', () => {
|
|
|
+ let spyFoo = sinon.spy();
|
|
|
+ let spyBar = sinon.spy();
|
|
|
+ let spyAbc = sinon.spy();
|
|
|
+ let spyFoo2 = sinon.spy();
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ // Mess up with callbacks order to check whether they are called in adding order.
|
|
|
+ emitter.on( 'foo', spyFoo );
|
|
|
+ emitter.on( 'foo:bar:abc', spyAbc );
|
|
|
+ emitter.on( 'foo:bar', spyBar );
|
|
|
|
|
|
- sinon.assert.called( spy1 );
|
|
|
- sinon.assert.called( spy2 );
|
|
|
- sinon.assert.called( spy3 );
|
|
|
- } );
|
|
|
+ // This tests whether generic callbacks are also added to specific callbacks lists.
|
|
|
+ emitter.on( 'foo', spyFoo2 );
|
|
|
|
|
|
- it( 'should take a callback off()', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy( ( event ) => {
|
|
|
- event.off();
|
|
|
- } );
|
|
|
- let spy3 = sinon.spy();
|
|
|
+ // All four callbacks should be fired.
|
|
|
+ emitter.fire( 'foo:bar:abc' );
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
- emitter.on( 'test', spy3 );
|
|
|
+ sinon.assert.callOrder( spyFoo, spyAbc, spyBar, spyFoo2 );
|
|
|
+ sinon.assert.calledOnce( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyAbc );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ sinon.assert.calledOnce( spyFoo2 );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
- emitter.fire( 'test' );
|
|
|
+ // Only callbacks for foo and foo:bar event should be called.
|
|
|
+ emitter.fire( 'foo:bar' );
|
|
|
|
|
|
- sinon.assert.calledTwice( spy1 );
|
|
|
- sinon.assert.calledOnce( spy2 );
|
|
|
- sinon.assert.calledTwice( spy3 );
|
|
|
- } );
|
|
|
+ sinon.assert.calledOnce( spyAbc );
|
|
|
+ sinon.assert.calledTwice( spyFoo );
|
|
|
+ sinon.assert.calledTwice( spyBar );
|
|
|
+ sinon.assert.calledTwice( spyFoo2 );
|
|
|
+
|
|
|
+ // Only callback for foo should be called as foo:abc has not been registered.
|
|
|
+ // Still, foo is a valid, existing namespace.
|
|
|
+ emitter.fire( 'foo:abc' );
|
|
|
|
|
|
- it( 'should take the callback off() even after stop()', () => {
|
|
|
- let spy1 = sinon.spy( ( event ) => {
|
|
|
- event.stop();
|
|
|
- event.off();
|
|
|
+ sinon.assert.calledOnce( spyAbc );
|
|
|
+ sinon.assert.calledTwice( spyBar );
|
|
|
+ sinon.assert.calledThrice( spyFoo );
|
|
|
+ sinon.assert.calledThrice( spyFoo2 );
|
|
|
} );
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ } );
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
+ describe( 'on', () => {
|
|
|
+ it( 'should stop()', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy( ( event ) => {
|
|
|
+ event.stop();
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy3 );
|
|
|
+ emitter.on( 'test', sinon.stub().throws() );
|
|
|
+ emitter.on( 'test', sinon.stub().throws() );
|
|
|
|
|
|
- sinon.assert.calledOnce( spy1 );
|
|
|
- sinon.assert.calledOnce( spy2 );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
-describe( 'once', () => {
|
|
|
- it( 'should be called just once', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
- let spy3 = sinon.spy();
|
|
|
+ sinon.assert.called( spy1 );
|
|
|
+ sinon.assert.called( spy2 );
|
|
|
+ sinon.assert.called( spy3 );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.once( 'test', spy2 );
|
|
|
- emitter.on( 'test', spy3 );
|
|
|
+ it( 'should take a callback off()', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy( ( event ) => {
|
|
|
+ event.off();
|
|
|
+ } );
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy3 );
|
|
|
|
|
|
- sinon.assert.calledTwice( spy1 );
|
|
|
- sinon.assert.calledOnce( spy2 );
|
|
|
- sinon.assert.calledTwice( spy3 );
|
|
|
- } );
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- it( 'should have proper scope', () => {
|
|
|
- let ctx = {};
|
|
|
+ sinon.assert.calledTwice( spy1 );
|
|
|
+ sinon.assert.calledOnce( spy2 );
|
|
|
+ sinon.assert.calledTwice( spy3 );
|
|
|
+ } );
|
|
|
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ it( 'should take the callback off() even after stop()', () => {
|
|
|
+ let spy1 = sinon.spy( ( event ) => {
|
|
|
+ event.stop();
|
|
|
+ event.off();
|
|
|
+ } );
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- emitter.once( 'test', spy1, { context: ctx } );
|
|
|
- emitter.once( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- sinon.assert.calledOn( spy1, ctx );
|
|
|
- sinon.assert.calledOn( spy2, emitter );
|
|
|
+ sinon.assert.calledOnce( spy1 );
|
|
|
+ sinon.assert.calledOnce( spy2 );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should have proper arguments', () => {
|
|
|
- let spy = sinon.spy();
|
|
|
+ describe( 'once', () => {
|
|
|
+ it( 'should be called just once', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
- emitter.once( 'test', spy );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.once( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy3 );
|
|
|
|
|
|
- emitter.fire( 'test', 1, 2, 3 );
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 1, 2, 3 );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ sinon.assert.calledTwice( spy1 );
|
|
|
+ sinon.assert.calledOnce( spy2 );
|
|
|
+ sinon.assert.calledTwice( spy3 );
|
|
|
+ } );
|
|
|
|
|
|
-describe( 'off', () => {
|
|
|
- it( 'should get callbacks off()', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
- let spy3 = sinon.spy();
|
|
|
+ it( 'should have proper scope', () => {
|
|
|
+ let ctx = {};
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
- emitter.on( 'test', spy3 );
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.once( 'test', spy1, { context: ctx } );
|
|
|
+ emitter.once( 'test', spy2 );
|
|
|
|
|
|
- emitter.off( 'test', spy2 );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
- emitter.fire( 'test' );
|
|
|
+ sinon.assert.calledOn( spy1, ctx );
|
|
|
+ sinon.assert.calledOn( spy2, emitter );
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.calledThrice( spy1 );
|
|
|
- sinon.assert.calledOnce( spy2 );
|
|
|
- sinon.assert.calledThrice( spy3 );
|
|
|
- } );
|
|
|
+ it( 'should have proper arguments', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
+
|
|
|
+ emitter.once( 'test', spy );
|
|
|
|
|
|
- it( 'should not fail with unknown events', () => {
|
|
|
- emitter.off( 'test', () => {} );
|
|
|
+ emitter.fire( 'test', 1, 2, 3 );
|
|
|
+
|
|
|
+ sinon.assert.calledWithExactly( spy, sinon.match.instanceOf( EventInfo ), 1, 2, 3 );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should remove all entries for the same callback', () => {
|
|
|
- let spy1 = sinon.spy().named( 1 );
|
|
|
- let spy2 = sinon.spy().named( 2 );
|
|
|
+ describe( 'off', () => {
|
|
|
+ it( 'should get callbacks off()', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
- emitter.on( 'test', spy1 );
|
|
|
- emitter.on( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy3 );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.off( 'test', spy1 );
|
|
|
+ emitter.off( 'test', spy2 );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- sinon.assert.callCount( spy1, 2 );
|
|
|
- sinon.assert.callCount( spy2, 4 );
|
|
|
- } );
|
|
|
+ sinon.assert.calledThrice( spy1 );
|
|
|
+ sinon.assert.calledOnce( spy2 );
|
|
|
+ sinon.assert.calledThrice( spy3 );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should remove the callback for given context only', () => {
|
|
|
- let spy = sinon.spy().named( 1 );
|
|
|
+ it( 'should not fail with unknown events', () => {
|
|
|
+ emitter.off( 'test', () => {} );
|
|
|
+ } );
|
|
|
|
|
|
- let ctx1 = { context: 1 };
|
|
|
- let ctx2 = { context: 2 };
|
|
|
+ it( 'should remove all entries for the same callback', () => {
|
|
|
+ let spy1 = sinon.spy().named( 1 );
|
|
|
+ let spy2 = sinon.spy().named( 2 );
|
|
|
|
|
|
- emitter.on( 'test', spy, { context: ctx1 } );
|
|
|
- emitter.on( 'test', spy, { context: ctx2 } );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
+ emitter.on( 'test', spy1 );
|
|
|
+ emitter.on( 'test', spy2 );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- spy.reset();
|
|
|
+ emitter.off( 'test', spy1 );
|
|
|
|
|
|
- emitter.off( 'test', spy, ctx1 );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ sinon.assert.callCount( spy1, 2 );
|
|
|
+ sinon.assert.callCount( spy2, 4 );
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.calledOnce( spy );
|
|
|
- sinon.assert.calledOn( spy, ctx2 );
|
|
|
- } );
|
|
|
+ it( 'should remove the callback for given context only', () => {
|
|
|
+ let spy = sinon.spy().named( 1 );
|
|
|
|
|
|
- it( 'should properly remove callbacks for namespaced events', () => {
|
|
|
- let spyFoo = sinon.spy();
|
|
|
- let spyAbc = sinon.spy();
|
|
|
- let spyBar = sinon.spy();
|
|
|
- let spyFoo2 = sinon.spy();
|
|
|
+ let ctx1 = { context: 1 };
|
|
|
+ let ctx2 = { context: 2 };
|
|
|
|
|
|
- emitter.on( 'foo', spyFoo );
|
|
|
- emitter.on( 'foo:bar:abc', spyAbc );
|
|
|
- emitter.on( 'foo:bar', spyBar );
|
|
|
- emitter.on( 'foo', spyFoo2 );
|
|
|
+ emitter.on( 'test', spy, { context: ctx1 } );
|
|
|
+ emitter.on( 'test', spy, { context: ctx2 } );
|
|
|
|
|
|
- emitter.off( 'foo', spyFoo );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- emitter.fire( 'foo:bar:abc' );
|
|
|
+ spy.reset();
|
|
|
|
|
|
- sinon.assert.calledOnce( spyAbc );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- sinon.assert.calledOnce( spyFoo2 );
|
|
|
- sinon.assert.notCalled( spyFoo );
|
|
|
+ emitter.off( 'test', spy, ctx1 );
|
|
|
|
|
|
- emitter.fire( 'foo:bar' );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
- sinon.assert.notCalled( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyAbc );
|
|
|
- sinon.assert.calledTwice( spyBar );
|
|
|
- sinon.assert.calledTwice( spyFoo2 );
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ sinon.assert.calledOn( spy, ctx2 );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'foo' );
|
|
|
+ it( 'should properly remove callbacks for namespaced events', () => {
|
|
|
+ let spyFoo = sinon.spy();
|
|
|
+ let spyAbc = sinon.spy();
|
|
|
+ let spyBar = sinon.spy();
|
|
|
+ let spyFoo2 = sinon.spy();
|
|
|
|
|
|
- sinon.assert.notCalled( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyAbc );
|
|
|
- sinon.assert.calledTwice( spyBar );
|
|
|
- sinon.assert.calledThrice( spyFoo2 );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ emitter.on( 'foo', spyFoo );
|
|
|
+ emitter.on( 'foo:bar:abc', spyAbc );
|
|
|
+ emitter.on( 'foo:bar', spyBar );
|
|
|
+ emitter.on( 'foo', spyFoo2 );
|
|
|
|
|
|
-describe( 'listenTo', () => {
|
|
|
- beforeEach( refreshListener );
|
|
|
+ emitter.off( 'foo', spyFoo );
|
|
|
|
|
|
- it( 'should properly register callbacks', () => {
|
|
|
- let spy = sinon.spy();
|
|
|
+ emitter.fire( 'foo:bar:abc' );
|
|
|
|
|
|
- listener.listenTo( emitter, 'test', spy );
|
|
|
+ sinon.assert.calledOnce( spyAbc );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ sinon.assert.calledOnce( spyFoo2 );
|
|
|
+ sinon.assert.notCalled( spyFoo );
|
|
|
|
|
|
- emitter.fire( 'test' );
|
|
|
+ emitter.fire( 'foo:bar' );
|
|
|
|
|
|
- sinon.assert.called( spy );
|
|
|
- } );
|
|
|
+ sinon.assert.notCalled( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyAbc );
|
|
|
+ sinon.assert.calledTwice( spyBar );
|
|
|
+ sinon.assert.calledTwice( spyFoo2 );
|
|
|
|
|
|
- it( 'should correctly listen to namespaced events', () => {
|
|
|
- let spyFoo = sinon.spy();
|
|
|
- let spyBar = sinon.spy();
|
|
|
+ emitter.fire( 'foo' );
|
|
|
|
|
|
- listener.listenTo( emitter, 'foo', spyFoo );
|
|
|
- listener.listenTo( emitter, 'foo:bar', spyBar );
|
|
|
+ sinon.assert.notCalled( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyAbc );
|
|
|
+ sinon.assert.calledTwice( spyBar );
|
|
|
+ sinon.assert.calledThrice( spyFoo2 );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
|
|
|
- emitter.fire( 'foo:bar' );
|
|
|
+ describe( 'listenTo', () => {
|
|
|
+ beforeEach( refreshListener );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
+ it( 'should properly register callbacks', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
- emitter.fire( 'foo' );
|
|
|
+ listener.listenTo( emitter, 'test', spy );
|
|
|
|
|
|
- sinon.assert.calledTwice( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ emitter.fire( 'test' );
|
|
|
|
|
|
-describe( 'stopListening', () => {
|
|
|
- beforeEach( refreshListener );
|
|
|
+ sinon.assert.called( spy );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should stop listening to given event callback', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ it( 'should correctly listen to namespaced events', () => {
|
|
|
+ let spyFoo = sinon.spy();
|
|
|
+ let spyBar = sinon.spy();
|
|
|
|
|
|
- listener.listenTo( emitter, 'event1', spy1 );
|
|
|
- listener.listenTo( emitter, 'event2', spy2 );
|
|
|
+ listener.listenTo( emitter, 'foo', spyFoo );
|
|
|
+ listener.listenTo( emitter, 'foo:bar', spyBar );
|
|
|
|
|
|
- emitter.fire( 'event1' );
|
|
|
- emitter.fire( 'event2' );
|
|
|
+ emitter.fire( 'foo:bar' );
|
|
|
|
|
|
- listener.stopListening( emitter, 'event1', spy1 );
|
|
|
+ sinon.assert.calledOnce( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
|
|
|
- emitter.fire( 'event1' );
|
|
|
- emitter.fire( 'event2' );
|
|
|
+ emitter.fire( 'foo' );
|
|
|
|
|
|
- sinon.assert.calledOnce( spy1 );
|
|
|
- sinon.assert.calledTwice( spy2 );
|
|
|
+ sinon.assert.calledTwice( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should stop listening to given event', () => {
|
|
|
- let spy1a = sinon.spy();
|
|
|
- let spy1b = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ describe( 'stopListening', () => {
|
|
|
+ beforeEach( refreshListener );
|
|
|
|
|
|
- listener.listenTo( emitter, 'event1', spy1a );
|
|
|
- listener.listenTo( emitter, 'event1', spy1b );
|
|
|
- listener.listenTo( emitter, 'event2', spy2 );
|
|
|
+ it( 'should stop listening to given event callback', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- emitter.fire( 'event1' );
|
|
|
- emitter.fire( 'event2' );
|
|
|
+ listener.listenTo( emitter, 'event1', spy1 );
|
|
|
+ listener.listenTo( emitter, 'event2', spy2 );
|
|
|
|
|
|
- listener.stopListening( emitter, 'event1' );
|
|
|
+ emitter.fire( 'event1' );
|
|
|
+ emitter.fire( 'event2' );
|
|
|
|
|
|
- emitter.fire( 'event1' );
|
|
|
- emitter.fire( 'event2' );
|
|
|
+ listener.stopListening( emitter, 'event1', spy1 );
|
|
|
|
|
|
- sinon.assert.calledOnce( spy1a );
|
|
|
- sinon.assert.calledOnce( spy1b );
|
|
|
- sinon.assert.calledTwice( spy2 );
|
|
|
- } );
|
|
|
+ emitter.fire( 'event1' );
|
|
|
+ emitter.fire( 'event2' );
|
|
|
|
|
|
- it( 'should stop listening to all events from given emitter', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ sinon.assert.calledOnce( spy1 );
|
|
|
+ sinon.assert.calledTwice( spy2 );
|
|
|
+ } );
|
|
|
|
|
|
- listener.listenTo( emitter, 'event1', spy1 );
|
|
|
- listener.listenTo( emitter, 'event2', spy2 );
|
|
|
+ it( 'should stop listening to given event', () => {
|
|
|
+ let spy1a = sinon.spy();
|
|
|
+ let spy1b = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- emitter.fire( 'event1' );
|
|
|
- emitter.fire( 'event2' );
|
|
|
+ listener.listenTo( emitter, 'event1', spy1a );
|
|
|
+ listener.listenTo( emitter, 'event1', spy1b );
|
|
|
+ listener.listenTo( emitter, 'event2', spy2 );
|
|
|
|
|
|
- listener.stopListening( emitter );
|
|
|
+ emitter.fire( 'event1' );
|
|
|
+ emitter.fire( 'event2' );
|
|
|
|
|
|
- emitter.fire( 'event1' );
|
|
|
- emitter.fire( 'event2' );
|
|
|
+ listener.stopListening( emitter, 'event1' );
|
|
|
|
|
|
- sinon.assert.calledOnce( spy1 );
|
|
|
- sinon.assert.calledOnce( spy2 );
|
|
|
- } );
|
|
|
+ emitter.fire( 'event1' );
|
|
|
+ emitter.fire( 'event2' );
|
|
|
|
|
|
- it( 'should stop listening to everything', () => {
|
|
|
- let spy1 = sinon.spy();
|
|
|
- let spy2 = sinon.spy();
|
|
|
+ sinon.assert.calledOnce( spy1a );
|
|
|
+ sinon.assert.calledOnce( spy1b );
|
|
|
+ sinon.assert.calledTwice( spy2 );
|
|
|
+ } );
|
|
|
|
|
|
- let emitter1 = getEmitterInstance();
|
|
|
- let emitter2 = getEmitterInstance();
|
|
|
+ it( 'should stop listening to all events from given emitter', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- listener.listenTo( emitter1, 'event1', spy1 );
|
|
|
- listener.listenTo( emitter2, 'event2', spy2 );
|
|
|
+ listener.listenTo( emitter, 'event1', spy1 );
|
|
|
+ listener.listenTo( emitter, 'event2', spy2 );
|
|
|
|
|
|
- expect( listener ).to.have.property( '_listeningTo' );
|
|
|
+ emitter.fire( 'event1' );
|
|
|
+ emitter.fire( 'event2' );
|
|
|
|
|
|
- emitter1.fire( 'event1' );
|
|
|
- emitter2.fire( 'event2' );
|
|
|
+ listener.stopListening( emitter );
|
|
|
|
|
|
- listener.stopListening();
|
|
|
+ emitter.fire( 'event1' );
|
|
|
+ emitter.fire( 'event2' );
|
|
|
|
|
|
- emitter1.fire( 'event1' );
|
|
|
- emitter2.fire( 'event2' );
|
|
|
+ sinon.assert.calledOnce( spy1 );
|
|
|
+ sinon.assert.calledOnce( spy2 );
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.calledOnce( spy1 );
|
|
|
- sinon.assert.calledOnce( spy2 );
|
|
|
+ it( 'should stop listening to everything', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- expect( listener ).to.not.have.property( '_listeningTo' );
|
|
|
- } );
|
|
|
+ let emitter1 = getEmitterInstance();
|
|
|
+ let emitter2 = getEmitterInstance();
|
|
|
|
|
|
- it( 'should not stop other emitters when a non-listened emitter is provided', () => {
|
|
|
- let spy = sinon.spy();
|
|
|
+ listener.listenTo( emitter1, 'event1', spy1 );
|
|
|
+ listener.listenTo( emitter2, 'event2', spy2 );
|
|
|
|
|
|
- let emitter1 = getEmitterInstance();
|
|
|
- let emitter2 = getEmitterInstance();
|
|
|
+ expect( listener ).to.have.property( '_listeningTo' );
|
|
|
|
|
|
- listener.listenTo( emitter1, 'test', spy );
|
|
|
+ emitter1.fire( 'event1' );
|
|
|
+ emitter2.fire( 'event2' );
|
|
|
|
|
|
- listener.stopListening( emitter2 );
|
|
|
+ listener.stopListening();
|
|
|
|
|
|
- emitter1.fire( 'test' );
|
|
|
+ emitter1.fire( 'event1' );
|
|
|
+ emitter2.fire( 'event2' );
|
|
|
|
|
|
- sinon.assert.called( spy );
|
|
|
- } );
|
|
|
+ sinon.assert.calledOnce( spy1 );
|
|
|
+ sinon.assert.calledOnce( spy2 );
|
|
|
|
|
|
- it( 'should correctly stop listening to namespaced events', () => {
|
|
|
- let spyFoo = sinon.spy();
|
|
|
- let spyBar = sinon.spy();
|
|
|
+ expect( listener ).to.not.have.property( '_listeningTo' );
|
|
|
+ } );
|
|
|
|
|
|
- listener.listenTo( emitter, 'foo', spyFoo );
|
|
|
- listener.listenTo( emitter, 'foo:bar', spyBar );
|
|
|
+ it( 'should not stop other emitters when a non-listened emitter is provided', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
- listener.stopListening( emitter, 'foo' );
|
|
|
+ let emitter1 = getEmitterInstance();
|
|
|
+ let emitter2 = getEmitterInstance();
|
|
|
|
|
|
- emitter.fire( 'foo:bar' );
|
|
|
+ listener.listenTo( emitter1, 'test', spy );
|
|
|
|
|
|
- sinon.assert.notCalled( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ listener.stopListening( emitter2 );
|
|
|
|
|
|
-describe( 'delegate', () => {
|
|
|
- it( 'should chain for a single event', () => {
|
|
|
- const emitter = getEmitterInstance();
|
|
|
+ emitter1.fire( 'test' );
|
|
|
|
|
|
- expect( emitter.delegate( 'foo' ) ).to.contain.keys( 'to' );
|
|
|
- } );
|
|
|
+ sinon.assert.called( spy );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should chain for multiple events', () => {
|
|
|
- const emitter = getEmitterInstance();
|
|
|
+ it( 'should correctly stop listening to namespaced events', () => {
|
|
|
+ let spyFoo = sinon.spy();
|
|
|
+ let spyBar = sinon.spy();
|
|
|
|
|
|
- expect( emitter.delegate( 'foo', 'bar' ) ).to.contain.keys( 'to' );
|
|
|
- } );
|
|
|
+ listener.listenTo( emitter, 'foo', spyFoo );
|
|
|
+ listener.listenTo( emitter, 'foo:bar', spyBar );
|
|
|
|
|
|
- describe( 'to', () => {
|
|
|
- it( 'forwards an event to another emitter', ( done ) => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const dataA = {};
|
|
|
- const dataB = {};
|
|
|
+ listener.stopListening( emitter, 'foo' );
|
|
|
|
|
|
- emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
+ emitter.fire( 'foo:bar' );
|
|
|
|
|
|
- emitterA.on( 'foo', ( ...args ) => {
|
|
|
- assertDelegated( args, {
|
|
|
- expectedSource: emitterB,
|
|
|
- expectedName: 'foo',
|
|
|
- expectedPath: [ emitterB, emitterA ],
|
|
|
- expectedData: [ dataA, dataB ]
|
|
|
- } );
|
|
|
+ sinon.assert.notCalled( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
|
|
|
- done();
|
|
|
- } );
|
|
|
+ describe( 'delegate', () => {
|
|
|
+ it( 'should chain for a single event', () => {
|
|
|
+ const emitter = getEmitterInstance();
|
|
|
|
|
|
- emitterB.fire( 'foo', dataA, dataB );
|
|
|
+ expect( emitter.delegate( 'foo' ) ).to.contain.keys( 'to' );
|
|
|
} );
|
|
|
|
|
|
- it( 'forwards multiple events to another emitter', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyFoo = sinon.spy();
|
|
|
- const spyBar = sinon.spy();
|
|
|
- const spyBaz = sinon.spy();
|
|
|
- const dataA = {};
|
|
|
- const dataB = {};
|
|
|
+ it( 'should chain for multiple events', () => {
|
|
|
+ const emitter = getEmitterInstance();
|
|
|
|
|
|
- emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA );
|
|
|
-
|
|
|
- emitterA.on( 'foo', spyFoo );
|
|
|
- emitterA.on( 'bar', spyBar );
|
|
|
- emitterA.on( 'baz', spyBaz );
|
|
|
+ expect( emitter.delegate( 'foo', 'bar' ) ).to.contain.keys( 'to' );
|
|
|
+ } );
|
|
|
|
|
|
- emitterB.fire( 'foo', dataA, dataB );
|
|
|
+ describe( 'to', () => {
|
|
|
+ it( 'forwards an event to another emitter', ( done ) => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const dataA = {};
|
|
|
+ const dataB = {};
|
|
|
|
|
|
- sinon.assert.calledOnce( spyFoo );
|
|
|
- sinon.assert.notCalled( spyBar );
|
|
|
- sinon.assert.notCalled( spyBaz );
|
|
|
-
|
|
|
- assertDelegated( spyFoo.args[ 0 ], {
|
|
|
- expectedSource: emitterB,
|
|
|
- expectedName: 'foo',
|
|
|
- expectedPath: [ emitterB, emitterA ],
|
|
|
- expectedData: [ dataA, dataB ]
|
|
|
- } );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterA.on( 'foo', ( ...args ) => {
|
|
|
+ assertDelegated( args, {
|
|
|
+ expectedSource: emitterB,
|
|
|
+ expectedName: 'foo',
|
|
|
+ expectedPath: [ emitterB, emitterA ],
|
|
|
+ expectedData: [ dataA, dataB ]
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- sinon.assert.notCalled( spyBaz );
|
|
|
+ done();
|
|
|
+ } );
|
|
|
|
|
|
- assertDelegated( spyBar.args[ 0 ], {
|
|
|
- expectedSource: emitterB,
|
|
|
- expectedName: 'bar',
|
|
|
- expectedPath: [ emitterB, emitterA ],
|
|
|
- expectedData: []
|
|
|
+ emitterB.fire( 'foo', dataA, dataB );
|
|
|
} );
|
|
|
|
|
|
- emitterB.fire( 'baz' );
|
|
|
+ it( 'forwards multiple events to another emitter', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyFoo = sinon.spy();
|
|
|
+ const spyBar = sinon.spy();
|
|
|
+ const spyBaz = sinon.spy();
|
|
|
+ const dataA = {};
|
|
|
+ const dataB = {};
|
|
|
|
|
|
- sinon.assert.calledOnce( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- sinon.assert.calledOnce( spyBaz );
|
|
|
+ emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA );
|
|
|
|
|
|
- assertDelegated( spyBaz.args[ 0 ], {
|
|
|
- expectedSource: emitterB,
|
|
|
- expectedName: 'baz',
|
|
|
- expectedPath: [ emitterB, emitterA ],
|
|
|
- expectedData: []
|
|
|
- } );
|
|
|
+ emitterA.on( 'foo', spyFoo );
|
|
|
+ emitterA.on( 'bar', spyBar );
|
|
|
+ emitterA.on( 'baz', spyBaz );
|
|
|
|
|
|
- emitterB.fire( 'not-delegated' );
|
|
|
+ emitterB.fire( 'foo', dataA, dataB );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyFoo );
|
|
|
- sinon.assert.calledOnce( spyBar );
|
|
|
- sinon.assert.calledOnce( spyBaz );
|
|
|
- } );
|
|
|
+ sinon.assert.calledOnce( spyFoo );
|
|
|
+ sinon.assert.notCalled( spyBar );
|
|
|
+ sinon.assert.notCalled( spyBaz );
|
|
|
|
|
|
- it( 'does not forward events which are not supposed to be delegated', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyFoo = sinon.spy();
|
|
|
- const spyBar = sinon.spy();
|
|
|
- const spyBaz = sinon.spy();
|
|
|
-
|
|
|
- emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA );
|
|
|
+ assertDelegated( spyFoo.args[ 0 ], {
|
|
|
+ expectedSource: emitterB,
|
|
|
+ expectedName: 'foo',
|
|
|
+ expectedPath: [ emitterB, emitterA ],
|
|
|
+ expectedData: [ dataA, dataB ]
|
|
|
+ } );
|
|
|
|
|
|
- emitterA.on( 'foo', spyFoo );
|
|
|
- emitterA.on( 'bar', spyBar );
|
|
|
- emitterA.on( 'baz', spyBaz );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
- emitterB.fire( 'baz' );
|
|
|
- emitterB.fire( 'not-delegated' );
|
|
|
+ sinon.assert.calledOnce( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ sinon.assert.notCalled( spyBaz );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFoo, spyBar, spyBaz );
|
|
|
- sinon.assert.callCount( spyFoo, 1 );
|
|
|
- sinon.assert.callCount( spyBar, 1 );
|
|
|
- sinon.assert.callCount( spyBaz, 1 );
|
|
|
- } );
|
|
|
+ assertDelegated( spyBar.args[ 0 ], {
|
|
|
+ expectedSource: emitterB,
|
|
|
+ expectedName: 'bar',
|
|
|
+ expectedPath: [ emitterB, emitterA ],
|
|
|
+ expectedData: []
|
|
|
+ } );
|
|
|
|
|
|
- it( 'supports deep chain event delegation', ( done ) => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const data = {};
|
|
|
+ emitterB.fire( 'baz' );
|
|
|
|
|
|
- emitterC.delegate( 'foo' ).to( emitterB );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
+ sinon.assert.calledOnce( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ sinon.assert.calledOnce( spyBaz );
|
|
|
|
|
|
- emitterA.on( 'foo', ( ...args ) => {
|
|
|
- assertDelegated( args, {
|
|
|
- expectedSource: emitterC,
|
|
|
- expectedName: 'foo',
|
|
|
- expectedPath: [ emitterC, emitterB, emitterA ],
|
|
|
- expectedData: [ data ]
|
|
|
+ assertDelegated( spyBaz.args[ 0 ], {
|
|
|
+ expectedSource: emitterB,
|
|
|
+ expectedName: 'baz',
|
|
|
+ expectedPath: [ emitterB, emitterA ],
|
|
|
+ expectedData: []
|
|
|
} );
|
|
|
|
|
|
- done();
|
|
|
+ emitterB.fire( 'not-delegated' );
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spyFoo );
|
|
|
+ sinon.assert.calledOnce( spyBar );
|
|
|
+ sinon.assert.calledOnce( spyBaz );
|
|
|
} );
|
|
|
|
|
|
- emitterC.fire( 'foo', data );
|
|
|
- } );
|
|
|
+ it( 'does not forward events which are not supposed to be delegated', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyFoo = sinon.spy();
|
|
|
+ const spyBar = sinon.spy();
|
|
|
+ const spyBaz = sinon.spy();
|
|
|
|
|
|
- it( 'preserves path in event delegation', ( done ) => {
|
|
|
- const data = {};
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const emitterD = getEmitterInstance();
|
|
|
+ emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA );
|
|
|
|
|
|
- emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterC );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterD );
|
|
|
+ emitterA.on( 'foo', spyFoo );
|
|
|
+ emitterA.on( 'bar', spyBar );
|
|
|
+ emitterA.on( 'baz', spyBaz );
|
|
|
|
|
|
- emitterD.on( 'foo', ( ...args ) => {
|
|
|
- assertDelegated( args, {
|
|
|
- expectedSource: emitterB,
|
|
|
- expectedName: 'foo',
|
|
|
- expectedPath: [ emitterB, emitterD ],
|
|
|
- expectedData: [ data ]
|
|
|
- } );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'baz' );
|
|
|
+ emitterB.fire( 'not-delegated' );
|
|
|
|
|
|
- done();
|
|
|
+ sinon.assert.callOrder( spyFoo, spyBar, spyBaz );
|
|
|
+ sinon.assert.callCount( spyFoo, 1 );
|
|
|
+ sinon.assert.callCount( spyBar, 1 );
|
|
|
+ sinon.assert.callCount( spyBaz, 1 );
|
|
|
} );
|
|
|
|
|
|
- emitterB.fire( 'foo', data );
|
|
|
- emitterC.fire( 'foo', data );
|
|
|
- } );
|
|
|
+ it( 'supports deep chain event delegation', ( done ) => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const data = {};
|
|
|
|
|
|
- it( 'executes callbacks first, then delegates further', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyA = sinon.spy();
|
|
|
- const spyB = sinon.spy();
|
|
|
+ emitterC.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
|
|
|
- emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
+ emitterA.on( 'foo', ( ...args ) => {
|
|
|
+ assertDelegated( args, {
|
|
|
+ expectedSource: emitterC,
|
|
|
+ expectedName: 'foo',
|
|
|
+ expectedPath: [ emitterC, emitterB, emitterA ],
|
|
|
+ expectedData: [ data ]
|
|
|
+ } );
|
|
|
|
|
|
- emitterA.on( 'foo', spyA );
|
|
|
- emitterB.on( 'foo', spyB );
|
|
|
+ done();
|
|
|
+ } );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
+ emitterC.fire( 'foo', data );
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.callOrder( spyB, spyA );
|
|
|
- } );
|
|
|
+ it( 'preserves path in event delegation', ( done ) => {
|
|
|
+ const data = {};
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const emitterD = getEmitterInstance();
|
|
|
+
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterC );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterD );
|
|
|
+
|
|
|
+ emitterD.on( 'foo', ( ...args ) => {
|
|
|
+ assertDelegated( args, {
|
|
|
+ expectedSource: emitterB,
|
|
|
+ expectedName: 'foo',
|
|
|
+ expectedPath: [ emitterB, emitterD ],
|
|
|
+ expectedData: [ data ]
|
|
|
+ } );
|
|
|
+
|
|
|
+ done();
|
|
|
+ } );
|
|
|
|
|
|
- it( 'supports delegation under a different name', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const emitterD = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyCBaz = sinon.spy();
|
|
|
- const spyDFoo = sinon.spy();
|
|
|
+ emitterB.fire( 'foo', data );
|
|
|
+ emitterC.fire( 'foo', data );
|
|
|
+ } );
|
|
|
|
|
|
- emitterB.delegate( 'foo' ).to( emitterA, 'bar' );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterC, name => name + '-baz' );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterD );
|
|
|
+ it( 'executes callbacks first, then delegates further', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyA = sinon.spy();
|
|
|
+ const spyB = sinon.spy();
|
|
|
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterC.on( 'foo-baz', spyCBaz );
|
|
|
- emitterD.on( 'foo', spyDFoo );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterA );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
+ emitterA.on( 'foo', spyA );
|
|
|
+ emitterB.on( 'foo', spyB );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyABar );
|
|
|
- sinon.assert.calledOnce( spyCBaz );
|
|
|
- sinon.assert.calledOnce( spyDFoo );
|
|
|
- sinon.assert.notCalled( spyAFoo );
|
|
|
- } );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
|
|
|
- it( 'supports delegation under a different name with multiple events', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyABaz = sinon.spy();
|
|
|
- const spyAQux = sinon.spy();
|
|
|
+ sinon.assert.callOrder( spyB, spyA );
|
|
|
+ } );
|
|
|
|
|
|
- emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA, 'qux' );
|
|
|
+ it( 'supports delegation under a different name', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const emitterD = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyCBaz = sinon.spy();
|
|
|
+ const spyDFoo = sinon.spy();
|
|
|
+
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterA, 'bar' );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterC, name => name + '-baz' );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterD );
|
|
|
+
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterC.on( 'foo-baz', spyCBaz );
|
|
|
+ emitterD.on( 'foo', spyDFoo );
|
|
|
+
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spyABar );
|
|
|
+ sinon.assert.calledOnce( spyCBaz );
|
|
|
+ sinon.assert.calledOnce( spyDFoo );
|
|
|
+ sinon.assert.notCalled( spyAFoo );
|
|
|
+ } );
|
|
|
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterA.on( 'baz', spyABaz );
|
|
|
- emitterA.on( 'qux', spyAQux );
|
|
|
+ it( 'supports delegation under a different name with multiple events', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyABaz = sinon.spy();
|
|
|
+ const spyAQux = sinon.spy();
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'baz' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA, 'qux' );
|
|
|
|
|
|
- sinon.assert.notCalled( spyAFoo );
|
|
|
- sinon.assert.notCalled( spyABar );
|
|
|
- sinon.assert.notCalled( spyABaz );
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterA.on( 'baz', spyABaz );
|
|
|
+ emitterA.on( 'qux', spyAQux );
|
|
|
|
|
|
- sinon.assert.calledThrice( spyAQux );
|
|
|
- } );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'baz' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- it( 'supports delegation with multiple events, each under a different name', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyABaz = sinon.spy();
|
|
|
- const spyAFooQux = sinon.spy();
|
|
|
- const spyABarQux = sinon.spy();
|
|
|
- const spyABazQux = sinon.spy();
|
|
|
+ sinon.assert.notCalled( spyAFoo );
|
|
|
+ sinon.assert.notCalled( spyABar );
|
|
|
+ sinon.assert.notCalled( spyABaz );
|
|
|
|
|
|
- emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA, name => name + '-qux' );
|
|
|
+ sinon.assert.calledThrice( spyAQux );
|
|
|
+ } );
|
|
|
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterA.on( 'baz', spyABaz );
|
|
|
+ it( 'supports delegation with multiple events, each under a different name', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyABaz = sinon.spy();
|
|
|
+ const spyAFooQux = sinon.spy();
|
|
|
+ const spyABarQux = sinon.spy();
|
|
|
+ const spyABazQux = sinon.spy();
|
|
|
|
|
|
- emitterA.on( 'foo-qux', spyAFooQux );
|
|
|
- emitterA.on( 'bar-qux', spyABarQux );
|
|
|
- emitterA.on( 'baz-qux', spyABazQux );
|
|
|
+ emitterB.delegate( 'foo', 'bar', 'baz' ).to( emitterA, name => name + '-qux' );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'baz' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterA.on( 'baz', spyABaz );
|
|
|
|
|
|
- sinon.assert.notCalled( spyAFoo );
|
|
|
- sinon.assert.notCalled( spyABar );
|
|
|
- sinon.assert.notCalled( spyABaz );
|
|
|
+ emitterA.on( 'foo-qux', spyAFooQux );
|
|
|
+ emitterA.on( 'bar-qux', spyABarQux );
|
|
|
+ emitterA.on( 'baz-qux', spyABazQux );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyAFooQux );
|
|
|
- sinon.assert.calledOnce( spyABarQux );
|
|
|
- sinon.assert.calledOnce( spyABazQux );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'baz' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyAFooQux, spyABazQux, spyABarQux );
|
|
|
- } );
|
|
|
+ sinon.assert.notCalled( spyAFoo );
|
|
|
+ sinon.assert.notCalled( spyABar );
|
|
|
+ sinon.assert.notCalled( spyABaz );
|
|
|
|
|
|
- it( 'preserves path in delegation under a different name', ( done ) => {
|
|
|
- const data = {};
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const emitterD = getEmitterInstance();
|
|
|
+ sinon.assert.calledOnce( spyAFooQux );
|
|
|
+ sinon.assert.calledOnce( spyABarQux );
|
|
|
+ sinon.assert.calledOnce( spyABazQux );
|
|
|
|
|
|
- emitterB.delegate( 'foo' ).to( emitterA, 'bar' );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterC, 'baz' );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterD );
|
|
|
+ sinon.assert.callOrder( spyAFooQux, spyABazQux, spyABarQux );
|
|
|
+ } );
|
|
|
|
|
|
- emitterD.on( 'foo', ( ...args ) => {
|
|
|
- assertDelegated( args, {
|
|
|
- expectedSource: emitterB,
|
|
|
- expectedName: 'foo',
|
|
|
- expectedPath: [ emitterB, emitterD ],
|
|
|
- expectedData: [ data ]
|
|
|
+ it( 'preserves path in delegation under a different name', ( done ) => {
|
|
|
+ const data = {};
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const emitterD = getEmitterInstance();
|
|
|
+
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterA, 'bar' );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterC, 'baz' );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterD );
|
|
|
+
|
|
|
+ emitterD.on( 'foo', ( ...args ) => {
|
|
|
+ assertDelegated( args, {
|
|
|
+ expectedSource: emitterB,
|
|
|
+ expectedName: 'foo',
|
|
|
+ expectedPath: [ emitterB, emitterD ],
|
|
|
+ expectedData: [ data ]
|
|
|
+ } );
|
|
|
+
|
|
|
+ done();
|
|
|
} );
|
|
|
|
|
|
- done();
|
|
|
+ emitterB.fire( 'foo', data );
|
|
|
} );
|
|
|
|
|
|
- emitterB.fire( 'foo', data );
|
|
|
- } );
|
|
|
+ it( 'supports delegation of all events', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyABaz = sinon.spy();
|
|
|
|
|
|
- it( 'supports delegation of all events', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyABaz = sinon.spy();
|
|
|
+ emitterB.delegate( '*' ).to( emitterA );
|
|
|
|
|
|
- emitterB.delegate( '*' ).to( emitterA );
|
|
|
-
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterA.on( 'baz', spyABaz );
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterA.on( 'baz', spyABaz );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'baz' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'baz' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyAFoo, spyABaz, spyABar );
|
|
|
- } );
|
|
|
+ sinon.assert.callOrder( spyAFoo, spyABaz, spyABar );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'supports delegation of all events under different names', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyABaz = sinon.spy();
|
|
|
- const spyAFooDel = sinon.spy();
|
|
|
- const spyABarDel = sinon.spy();
|
|
|
- const spyABazDel = sinon.spy();
|
|
|
+ it( 'supports delegation of all events under different names', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyABaz = sinon.spy();
|
|
|
+ const spyAFooDel = sinon.spy();
|
|
|
+ const spyABarDel = sinon.spy();
|
|
|
+ const spyABazDel = sinon.spy();
|
|
|
|
|
|
- emitterB.delegate( '*' ).to( emitterA, name => name + '-delegated' );
|
|
|
+ emitterB.delegate( '*' ).to( emitterA, name => name + '-delegated' );
|
|
|
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterA.on( 'baz', spyABaz );
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterA.on( 'baz', spyABaz );
|
|
|
|
|
|
- emitterA.on( 'foo-delegated', spyAFooDel );
|
|
|
- emitterA.on( 'bar-delegated', spyABarDel );
|
|
|
- emitterA.on( 'baz-delegated', spyABazDel );
|
|
|
+ emitterA.on( 'foo-delegated', spyAFooDel );
|
|
|
+ emitterA.on( 'bar-delegated', spyABarDel );
|
|
|
+ emitterA.on( 'baz-delegated', spyABazDel );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'baz' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'baz' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.notCalled( spyAFoo );
|
|
|
- sinon.assert.notCalled( spyABar );
|
|
|
- sinon.assert.notCalled( spyABaz );
|
|
|
+ sinon.assert.notCalled( spyAFoo );
|
|
|
+ sinon.assert.notCalled( spyABar );
|
|
|
+ sinon.assert.notCalled( spyABaz );
|
|
|
|
|
|
- sinon.assert.callOrder( spyAFooDel, spyABazDel, spyABarDel );
|
|
|
+ sinon.assert.callOrder( spyAFooDel, spyABazDel, spyABarDel );
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
-describe( 'stopDelegating', () => {
|
|
|
- it( 'passes if no delegation was set', () => {
|
|
|
- expect( () => {
|
|
|
- getEmitterInstance().stopDelegating();
|
|
|
- } ).to.not.throw();
|
|
|
- } );
|
|
|
+ describe( 'stopDelegating', () => {
|
|
|
+ it( 'passes if no delegation was set', () => {
|
|
|
+ expect( () => {
|
|
|
+ getEmitterInstance().stopDelegating();
|
|
|
+ } ).to.not.throw();
|
|
|
+ } );
|
|
|
|
|
|
- it( 'stops delegating all events to all emitters', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const spyFoo = sinon.spy();
|
|
|
- const spyBar = sinon.spy();
|
|
|
+ it( 'stops delegating all events to all emitters', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const spyFoo = sinon.spy();
|
|
|
+ const spyBar = sinon.spy();
|
|
|
|
|
|
- emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
- emitterA.delegate( 'bar' ).to( emitterC );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterA.delegate( 'bar' ).to( emitterC );
|
|
|
|
|
|
- emitterB.on( 'foo', spyFoo );
|
|
|
- emitterC.on( 'bar', spyBar );
|
|
|
+ emitterB.on( 'foo', spyFoo );
|
|
|
+ emitterC.on( 'bar', spyBar );
|
|
|
|
|
|
- emitterA.fire( 'foo' );
|
|
|
- emitterA.fire( 'bar' );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
+ emitterA.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFoo, spyBar );
|
|
|
+ sinon.assert.callOrder( spyFoo, spyBar );
|
|
|
|
|
|
- emitterA.stopDelegating();
|
|
|
+ emitterA.stopDelegating();
|
|
|
|
|
|
- emitterA.fire( 'foo' );
|
|
|
- emitterA.fire( 'bar' );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
+ emitterA.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFoo, spyBar );
|
|
|
- } );
|
|
|
+ sinon.assert.callOrder( spyFoo, spyBar );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'stops delegating a specific event to all emitters', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const spyFooB = sinon.spy();
|
|
|
- const spyFooC = sinon.spy();
|
|
|
- const spyBarC = sinon.spy();
|
|
|
+ it( 'stops delegating a specific event to all emitters', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const spyFooB = sinon.spy();
|
|
|
+ const spyFooC = sinon.spy();
|
|
|
+ const spyBarC = sinon.spy();
|
|
|
|
|
|
- emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
- emitterA.delegate( 'foo' ).to( emitterC );
|
|
|
- emitterA.delegate( 'bar' ).to( emitterC );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterC );
|
|
|
+ emitterA.delegate( 'bar' ).to( emitterC );
|
|
|
|
|
|
- emitterB.on( 'foo', spyFooB );
|
|
|
- emitterC.on( 'foo', spyFooC );
|
|
|
- emitterC.on( 'bar', spyBarC );
|
|
|
+ emitterB.on( 'foo', spyFooB );
|
|
|
+ emitterC.on( 'foo', spyFooC );
|
|
|
+ emitterC.on( 'bar', spyBarC );
|
|
|
|
|
|
- emitterA.fire( 'foo' );
|
|
|
- emitterA.fire( 'bar' );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
+ emitterA.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFooB, spyFooC, spyBarC );
|
|
|
+ sinon.assert.callOrder( spyFooB, spyFooC, spyBarC );
|
|
|
|
|
|
- emitterA.stopDelegating( 'foo' );
|
|
|
+ emitterA.stopDelegating( 'foo' );
|
|
|
|
|
|
- emitterA.fire( 'foo' );
|
|
|
- emitterA.fire( 'bar' );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
+ emitterA.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFooB, spyFooC, spyBarC, spyBarC );
|
|
|
- } );
|
|
|
+ sinon.assert.callOrder( spyFooB, spyFooC, spyBarC, spyBarC );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'stops delegating a specific event to a specific emitter', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const spyFooB = sinon.spy();
|
|
|
- const spyFooC = sinon.spy();
|
|
|
+ it( 'stops delegating a specific event to a specific emitter', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const spyFooB = sinon.spy();
|
|
|
+ const spyFooC = sinon.spy();
|
|
|
|
|
|
- emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
- emitterA.delegate( 'foo' ).to( emitterC );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterC );
|
|
|
|
|
|
- emitterB.on( 'foo', spyFooB );
|
|
|
- emitterC.on( 'foo', spyFooC );
|
|
|
+ emitterB.on( 'foo', spyFooB );
|
|
|
+ emitterC.on( 'foo', spyFooC );
|
|
|
|
|
|
- emitterA.fire( 'foo' );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFooB, spyFooC );
|
|
|
+ sinon.assert.callOrder( spyFooB, spyFooC );
|
|
|
|
|
|
- emitterA.stopDelegating( 'foo', emitterC );
|
|
|
- emitterA.fire( 'foo' );
|
|
|
+ emitterA.stopDelegating( 'foo', emitterC );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFooB, spyFooC, spyFooB );
|
|
|
- } );
|
|
|
+ sinon.assert.callOrder( spyFooB, spyFooC, spyFooB );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'stops delegating a specific event under a different name to a specific emitter', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const spyFooB = sinon.spy();
|
|
|
- const spyFooC = sinon.spy();
|
|
|
+ it( 'stops delegating a specific event under a different name to a specific emitter', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const spyFooB = sinon.spy();
|
|
|
+ const spyFooC = sinon.spy();
|
|
|
|
|
|
- emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
- emitterA.delegate( 'foo' ).to( emitterC, 'bar' );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterC, 'bar' );
|
|
|
|
|
|
- emitterB.on( 'foo', spyFooB );
|
|
|
- emitterC.on( 'bar', spyFooC );
|
|
|
+ emitterB.on( 'foo', spyFooB );
|
|
|
+ emitterC.on( 'bar', spyFooC );
|
|
|
|
|
|
- emitterA.fire( 'foo' );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFooB, spyFooC );
|
|
|
+ sinon.assert.callOrder( spyFooB, spyFooC );
|
|
|
|
|
|
- emitterA.stopDelegating( 'foo', emitterC );
|
|
|
- emitterA.fire( 'foo' );
|
|
|
+ emitterA.stopDelegating( 'foo', emitterC );
|
|
|
+ emitterA.fire( 'foo' );
|
|
|
|
|
|
- sinon.assert.callOrder( spyFooB, spyFooC, spyFooB );
|
|
|
- } );
|
|
|
+ sinon.assert.callOrder( spyFooB, spyFooC, spyFooB );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'stops delegating all ("*")', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyCFoo = sinon.spy();
|
|
|
- const spyCBar = sinon.spy();
|
|
|
+ it( 'stops delegating all ("*")', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyCFoo = sinon.spy();
|
|
|
+ const spyCBar = sinon.spy();
|
|
|
|
|
|
- emitterB.delegate( '*' ).to( emitterA );
|
|
|
- emitterB.delegate( '*' ).to( emitterC );
|
|
|
+ emitterB.delegate( '*' ).to( emitterA );
|
|
|
+ emitterB.delegate( '*' ).to( emitterC );
|
|
|
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterC.on( 'foo', spyCFoo );
|
|
|
- emitterC.on( 'bar', spyCBar );
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterC.on( 'foo', spyCFoo );
|
|
|
+ emitterC.on( 'bar', spyCBar );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyAFoo );
|
|
|
- sinon.assert.calledOnce( spyABar );
|
|
|
- sinon.assert.calledOnce( spyCFoo );
|
|
|
- sinon.assert.calledOnce( spyCBar );
|
|
|
+ sinon.assert.calledOnce( spyAFoo );
|
|
|
+ sinon.assert.calledOnce( spyABar );
|
|
|
+ sinon.assert.calledOnce( spyCFoo );
|
|
|
+ sinon.assert.calledOnce( spyCBar );
|
|
|
|
|
|
- emitterB.stopDelegating( '*' );
|
|
|
+ emitterB.stopDelegating( '*' );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyAFoo );
|
|
|
- sinon.assert.calledOnce( spyABar );
|
|
|
- sinon.assert.calledOnce( spyCFoo );
|
|
|
- sinon.assert.calledOnce( spyCBar );
|
|
|
- } );
|
|
|
+ sinon.assert.calledOnce( spyAFoo );
|
|
|
+ sinon.assert.calledOnce( spyABar );
|
|
|
+ sinon.assert.calledOnce( spyCFoo );
|
|
|
+ sinon.assert.calledOnce( spyCBar );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'stops delegating all ("*") to a specific emitter', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
- const spyAFoo = sinon.spy();
|
|
|
- const spyABar = sinon.spy();
|
|
|
- const spyCFoo = sinon.spy();
|
|
|
- const spyCBar = sinon.spy();
|
|
|
+ it( 'stops delegating all ("*") to a specific emitter', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
+ const spyAFoo = sinon.spy();
|
|
|
+ const spyABar = sinon.spy();
|
|
|
+ const spyCFoo = sinon.spy();
|
|
|
+ const spyCBar = sinon.spy();
|
|
|
|
|
|
- emitterB.delegate( '*' ).to( emitterA );
|
|
|
- emitterB.delegate( 'foo' ).to( emitterC );
|
|
|
+ emitterB.delegate( '*' ).to( emitterA );
|
|
|
+ emitterB.delegate( 'foo' ).to( emitterC );
|
|
|
|
|
|
- emitterA.on( 'foo', spyAFoo );
|
|
|
- emitterA.on( 'bar', spyABar );
|
|
|
- emitterC.on( 'foo', spyCFoo );
|
|
|
- emitterC.on( 'bar', spyCBar );
|
|
|
+ emitterA.on( 'foo', spyAFoo );
|
|
|
+ emitterA.on( 'bar', spyABar );
|
|
|
+ emitterC.on( 'foo', spyCFoo );
|
|
|
+ emitterC.on( 'bar', spyCBar );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyAFoo );
|
|
|
- sinon.assert.calledOnce( spyABar );
|
|
|
- sinon.assert.calledOnce( spyCFoo );
|
|
|
- sinon.assert.notCalled( spyCBar );
|
|
|
+ sinon.assert.calledOnce( spyAFoo );
|
|
|
+ sinon.assert.calledOnce( spyABar );
|
|
|
+ sinon.assert.calledOnce( spyCFoo );
|
|
|
+ sinon.assert.notCalled( spyCBar );
|
|
|
|
|
|
- emitterB.stopDelegating( '*', emitterA );
|
|
|
+ emitterB.stopDelegating( '*', emitterA );
|
|
|
|
|
|
- emitterB.fire( 'foo' );
|
|
|
- emitterB.fire( 'bar' );
|
|
|
+ emitterB.fire( 'foo' );
|
|
|
+ emitterB.fire( 'bar' );
|
|
|
|
|
|
- sinon.assert.calledOnce( spyAFoo );
|
|
|
- sinon.assert.calledOnce( spyABar );
|
|
|
- sinon.assert.calledTwice( spyCFoo );
|
|
|
- sinon.assert.notCalled( spyCBar );
|
|
|
- } );
|
|
|
+ sinon.assert.calledOnce( spyAFoo );
|
|
|
+ sinon.assert.calledOnce( spyABar );
|
|
|
+ sinon.assert.calledTwice( spyCFoo );
|
|
|
+ sinon.assert.notCalled( spyCBar );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'passes when stopping delegation of a specific event which has never been delegated', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
+ it( 'passes when stopping delegation of a specific event which has never been delegated', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
|
|
|
- expect( () => {
|
|
|
- emitterA.stopDelegating( 'bar' );
|
|
|
- emitterA.stopDelegating( 'bar', emitterB );
|
|
|
- } ).to.not.throw();
|
|
|
- } );
|
|
|
+ expect( () => {
|
|
|
+ emitterA.stopDelegating( 'bar' );
|
|
|
+ emitterA.stopDelegating( 'bar', emitterB );
|
|
|
+ } ).to.not.throw();
|
|
|
+ } );
|
|
|
|
|
|
- it( 'passes when stopping delegation of a specific event to an emitter which wasn\'t a destination', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
+ it( 'passes when stopping delegation of a specific event to an emitter which wasn\'t a destination', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
|
|
|
- emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
|
|
|
- expect( () => {
|
|
|
- emitterA.stopDelegating( 'foo', emitterC );
|
|
|
- } ).to.not.throw();
|
|
|
- } );
|
|
|
+ expect( () => {
|
|
|
+ emitterA.stopDelegating( 'foo', emitterC );
|
|
|
+ } ).to.not.throw();
|
|
|
+ } );
|
|
|
|
|
|
- it( 'passes when stopping delegation of a specific event to a specific emitter which has never been delegated', () => {
|
|
|
- const emitterA = getEmitterInstance();
|
|
|
- const emitterB = getEmitterInstance();
|
|
|
- const emitterC = getEmitterInstance();
|
|
|
+ it( 'passes when stopping delegation of a specific event to a specific emitter which has never been delegated', () => {
|
|
|
+ const emitterA = getEmitterInstance();
|
|
|
+ const emitterB = getEmitterInstance();
|
|
|
+ const emitterC = getEmitterInstance();
|
|
|
|
|
|
- emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
+ emitterA.delegate( 'foo' ).to( emitterB );
|
|
|
|
|
|
- expect( () => {
|
|
|
- emitterA.stopDelegating( 'bar', emitterC );
|
|
|
- } ).to.not.throw();
|
|
|
+ expect( () => {
|
|
|
+ emitterA.stopDelegating( 'bar', emitterC );
|
|
|
+ } ).to.not.throw();
|
|
|
+ } );
|
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
-function refreshEmitter() {
|
|
|
- emitter = getEmitterInstance();
|
|
|
-}
|
|
|
+ function refreshEmitter() {
|
|
|
+ emitter = getEmitterInstance();
|
|
|
+ }
|
|
|
|
|
|
-function refreshListener() {
|
|
|
- listener = getEmitterInstance();
|
|
|
-}
|
|
|
+ function refreshListener() {
|
|
|
+ listener = getEmitterInstance();
|
|
|
+ }
|
|
|
|
|
|
-function getEmitterInstance() {
|
|
|
- return Object.create( EmitterMixin );
|
|
|
-}
|
|
|
+ function getEmitterInstance() {
|
|
|
+ return Object.create( EmitterMixin );
|
|
|
+ }
|
|
|
|
|
|
-function assertDelegated( evtArgs, { expectedName, expectedSource, expectedPath, expectedData } ) {
|
|
|
- const evtInfo = evtArgs[ 0 ];
|
|
|
+ function assertDelegated( evtArgs, { expectedName, expectedSource, expectedPath, expectedData } ) {
|
|
|
+ const evtInfo = evtArgs[ 0 ];
|
|
|
|
|
|
- expect( evtInfo.name ).to.equal( expectedName );
|
|
|
- expect( evtInfo.source ).to.equal( expectedSource );
|
|
|
- expect( evtInfo.path ).to.deep.equal( expectedPath );
|
|
|
- expect( evtArgs.slice( 1 ) ).to.deep.equal( expectedData );
|
|
|
-}
|
|
|
+ expect( evtInfo.name ).to.equal( expectedName );
|
|
|
+ expect( evtInfo.source ).to.equal( expectedSource );
|
|
|
+ expect( evtInfo.path ).to.deep.equal( expectedPath );
|
|
|
+ expect( evtArgs.slice( 1 ) ).to.deep.equal( expectedData );
|
|
|
+ }
|
|
|
+} );
|