|
|
@@ -5,17 +5,17 @@
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
-var modules = bender.amd.require( 'emittermixin', 'eventinfo', 'utils' );
|
|
|
+const modules = bender.amd.require( 'emittermixin', 'eventinfo', 'utils' );
|
|
|
|
|
|
-var emitter, listener;
|
|
|
+let emitter, listener;
|
|
|
|
|
|
beforeEach( refreshEmitter );
|
|
|
|
|
|
-describe( 'fire', function() {
|
|
|
- it( 'should execute callbacks in the right order without priority', function() {
|
|
|
- var spy1 = sinon.spy().named( 1 );
|
|
|
- var spy2 = sinon.spy().named( 2 );
|
|
|
- var 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 );
|
|
|
@@ -26,12 +26,12 @@ describe( 'fire', function() {
|
|
|
sinon.assert.callOrder( spy1, spy2, spy3 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should execute callbacks in the right order with priority defined', function() {
|
|
|
- var spy1 = sinon.spy().named( 1 );
|
|
|
- var spy2 = sinon.spy().named( 2 );
|
|
|
- var spy3 = sinon.spy().named( 3 );
|
|
|
- var spy4 = sinon.spy().named( 4 );
|
|
|
- var spy5 = sinon.spy().named( 5 );
|
|
|
+ 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, null, 9 );
|
|
|
emitter.on( 'test', spy3 ); // Defaults to 10.
|
|
|
@@ -44,11 +44,11 @@ describe( 'fire', function() {
|
|
|
sinon.assert.callOrder( spy1, spy2, spy3, spy4, spy5 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should pass arguments to callbacks', function() {
|
|
|
- var EventInfo = modules.eventinfo;
|
|
|
+ it( 'should pass arguments to callbacks', () => {
|
|
|
+ const EventInfo = modules.eventinfo;
|
|
|
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy1 );
|
|
|
emitter.on( 'test', spy2 );
|
|
|
@@ -59,13 +59,13 @@ describe( 'fire', function() {
|
|
|
sinon.assert.calledWithExactly( spy2, sinon.match.instanceOf( EventInfo ), 1, 'b', true );
|
|
|
} );
|
|
|
|
|
|
- it( 'should pass proper context to callbacks', function() {
|
|
|
- var ctx1 = {};
|
|
|
- var ctx2 = {};
|
|
|
+ it( 'should pass proper context to callbacks', () => {
|
|
|
+ let ctx1 = {};
|
|
|
+ let ctx2 = {};
|
|
|
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
- var spy3 = sinon.spy();
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy1, ctx1 );
|
|
|
emitter.on( 'test', spy2, ctx2 );
|
|
|
@@ -78,9 +78,9 @@ describe( 'fire', function() {
|
|
|
sinon.assert.calledOn( spy3, emitter );
|
|
|
} );
|
|
|
|
|
|
- it( 'should fire the right event', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ it( 'should fire the right event', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
emitter.on( '1', spy1 );
|
|
|
emitter.on( '2', spy2 );
|
|
|
@@ -91,8 +91,8 @@ describe( 'fire', function() {
|
|
|
sinon.assert.called( spy2 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should execute callbacks many times', function() {
|
|
|
- var spy = sinon.spy();
|
|
|
+ it( 'should execute callbacks many times', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy );
|
|
|
|
|
|
@@ -103,12 +103,12 @@ describe( 'fire', function() {
|
|
|
sinon.assert.calledThrice( spy );
|
|
|
} );
|
|
|
|
|
|
- it( 'should do nothing for a non listened event', function() {
|
|
|
+ it( 'should do nothing for a non listened event', () => {
|
|
|
emitter.fire( 'test' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should accept the same callback many times', function() {
|
|
|
- var spy = sinon.spy();
|
|
|
+ it( 'should accept the same callback many times', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy );
|
|
|
emitter.on( 'test', spy );
|
|
|
@@ -120,11 +120,11 @@ describe( 'fire', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'on', function() {
|
|
|
- it( 'should stop()', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
- var spy3 = sinon.spy( function( event ) {
|
|
|
+describe( 'on', () => {
|
|
|
+ it( 'should stop()', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy( ( event ) => {
|
|
|
event.stop();
|
|
|
} );
|
|
|
|
|
|
@@ -141,12 +141,12 @@ describe( 'on', function() {
|
|
|
sinon.assert.called( spy3 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should take a callback off()', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy( function( event ) {
|
|
|
+ it( 'should take a callback off()', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy( ( event ) => {
|
|
|
event.off();
|
|
|
} );
|
|
|
- var spy3 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy1 );
|
|
|
emitter.on( 'test', spy2 );
|
|
|
@@ -160,12 +160,12 @@ describe( 'on', function() {
|
|
|
sinon.assert.calledTwice( spy3 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should take the callback off() even after stop()', function() {
|
|
|
- var spy1 = sinon.spy( function( event ) {
|
|
|
+ it( 'should take the callback off() even after stop()', () => {
|
|
|
+ let spy1 = sinon.spy( ( event ) => {
|
|
|
event.stop();
|
|
|
event.off();
|
|
|
} );
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy1 );
|
|
|
emitter.on( 'test', spy2 );
|
|
|
@@ -178,11 +178,11 @@ describe( 'on', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'once', function() {
|
|
|
- it( 'should be called just once', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
- var spy3 = sinon.spy();
|
|
|
+describe( 'once', () => {
|
|
|
+ it( 'should be called just once', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
+ let spy3 = sinon.spy();
|
|
|
|
|
|
emitter.on( 'test', spy1 );
|
|
|
emitter.once( 'test', spy2 );
|
|
|
@@ -196,11 +196,11 @@ describe( 'once', function() {
|
|
|
sinon.assert.calledTwice( spy3 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should have proper scope', function() {
|
|
|
- var ctx = {};
|
|
|
+ it( 'should have proper scope', () => {
|
|
|
+ let ctx = {};
|
|
|
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
emitter.once( 'test', spy1, ctx );
|
|
|
emitter.once( 'test', spy2 );
|
|
|
@@ -211,10 +211,10 @@ describe( 'once', function() {
|
|
|
sinon.assert.calledOn( spy2, emitter );
|
|
|
} );
|
|
|
|
|
|
- it( 'should have proper arguments', function() {
|
|
|
- var EventInfo = modules.eventinfo;
|
|
|
+ it( 'should have proper arguments', () => {
|
|
|
+ const EventInfo = modules.eventinfo;
|
|
|
|
|
|
- var spy = sinon.spy();
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
emitter.once( 'test', spy );
|
|
|
|
|
|
@@ -224,11 +224,11 @@ describe( 'once', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'off', function() {
|
|
|
- it( 'should get callbacks off()', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
- var spy3 = sinon.spy();
|
|
|
+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 );
|
|
|
@@ -246,13 +246,13 @@ describe( 'off', function() {
|
|
|
sinon.assert.calledThrice( spy3 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should not fail with unknown events', function() {
|
|
|
- emitter.off( 'test', function() {} );
|
|
|
+ it( 'should not fail with unknown events', () => {
|
|
|
+ emitter.off( 'test', () => {} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should remove all entries for the same callback', function() {
|
|
|
- var spy1 = sinon.spy().named( 1 );
|
|
|
- var spy2 = sinon.spy().named( 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', spy1 );
|
|
|
emitter.on( 'test', spy2 );
|
|
|
@@ -269,11 +269,11 @@ describe( 'off', function() {
|
|
|
sinon.assert.callCount( spy2, 4 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should remove the callback for a specific context only', function() {
|
|
|
- var spy = sinon.spy().named( 1 );
|
|
|
+ it( 'should remove the callback for a specific context only', () => {
|
|
|
+ let spy = sinon.spy().named( 1 );
|
|
|
|
|
|
- var ctx1 = { ctx: 1 };
|
|
|
- var ctx2 = { ctx: 2 };
|
|
|
+ let ctx1 = { ctx: 1 };
|
|
|
+ let ctx2 = { ctx: 2 };
|
|
|
|
|
|
emitter.on( 'test', spy, ctx1 );
|
|
|
emitter.on( 'test', spy, ctx2 );
|
|
|
@@ -291,11 +291,11 @@ describe( 'off', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'listenTo', function() {
|
|
|
+describe( 'listenTo', () => {
|
|
|
beforeEach( refreshListener );
|
|
|
|
|
|
- it( 'should properly register callbacks', function() {
|
|
|
- var spy = sinon.spy();
|
|
|
+ it( 'should properly register callbacks', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
listener.listenTo( emitter, 'test', spy );
|
|
|
|
|
|
@@ -305,12 +305,12 @@ describe( 'listenTo', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'stopListening', function() {
|
|
|
+describe( 'stopListening', () => {
|
|
|
beforeEach( refreshListener );
|
|
|
|
|
|
- it( 'should stop listening to a specific event callback', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ it( 'should stop listening to a specific event callback', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
listener.listenTo( emitter, 'event1', spy1 );
|
|
|
listener.listenTo( emitter, 'event2', spy2 );
|
|
|
@@ -327,10 +327,10 @@ describe( 'stopListening', function() {
|
|
|
sinon.assert.calledTwice( spy2 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should stop listening to an specific event', function() {
|
|
|
- var spy1a = sinon.spy();
|
|
|
- var spy1b = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ it( 'should stop listening to an specific event', () => {
|
|
|
+ let spy1a = sinon.spy();
|
|
|
+ let spy1b = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
listener.listenTo( emitter, 'event1', spy1a );
|
|
|
listener.listenTo( emitter, 'event1', spy1b );
|
|
|
@@ -349,9 +349,9 @@ describe( 'stopListening', function() {
|
|
|
sinon.assert.calledTwice( spy2 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should stop listening to all events from a specific emitter', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ it( 'should stop listening to all events from a specific emitter', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
listener.listenTo( emitter, 'event1', spy1 );
|
|
|
listener.listenTo( emitter, 'event2', spy2 );
|
|
|
@@ -368,12 +368,12 @@ describe( 'stopListening', function() {
|
|
|
sinon.assert.calledOnce( spy2 );
|
|
|
} );
|
|
|
|
|
|
- it( 'should stop listening to everything', function() {
|
|
|
- var spy1 = sinon.spy();
|
|
|
- var spy2 = sinon.spy();
|
|
|
+ it( 'should stop listening to everything', () => {
|
|
|
+ let spy1 = sinon.spy();
|
|
|
+ let spy2 = sinon.spy();
|
|
|
|
|
|
- var emitter1 = getEmitterInstance();
|
|
|
- var emitter2 = getEmitterInstance();
|
|
|
+ let emitter1 = getEmitterInstance();
|
|
|
+ let emitter2 = getEmitterInstance();
|
|
|
|
|
|
listener.listenTo( emitter1, 'event1', spy1 );
|
|
|
listener.listenTo( emitter2, 'event2', spy2 );
|
|
|
@@ -394,11 +394,11 @@ describe( 'stopListening', function() {
|
|
|
expect( listener ).to.not.have.property( '_listeningTo' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should not stop other emitters when a non-listened emitter is provided', function() {
|
|
|
- var spy = sinon.spy();
|
|
|
+ it( 'should not stop other emitters when a non-listened emitter is provided', () => {
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
- var emitter1 = getEmitterInstance();
|
|
|
- var emitter2 = getEmitterInstance();
|
|
|
+ let emitter1 = getEmitterInstance();
|
|
|
+ let emitter2 = getEmitterInstance();
|
|
|
|
|
|
listener.listenTo( emitter1, 'test', spy );
|
|
|
|
|
|
@@ -419,8 +419,8 @@ function refreshListener() {
|
|
|
}
|
|
|
|
|
|
function getEmitterInstance() {
|
|
|
- var EmitterMixin = modules.emittermixin;
|
|
|
- var utils = modules.utils;
|
|
|
+ const EmitterMixin = modules.emittermixin;
|
|
|
+ let utils = modules.utils;
|
|
|
|
|
|
return utils.extend( {}, EmitterMixin );
|
|
|
}
|