Jelajahi Sumber

Removed unncessary code and added missing tests.

Piotrek Koszuliński 8 tahun lalu
induk
melakukan
7080e06109

+ 0 - 6
packages/ckeditor5-utils/src/emittermixin.js

@@ -504,15 +504,9 @@ function createEventNamespace( source, eventName ) {
 // Gets an array containing callbacks list for a given event and it's more specific events.
 // I.e. if given event is foo:bar and there is also foo:bar:abc event registered, this will
 // return callback list of foo:bar and foo:bar:abc (but not foo).
-// Returns empty array if given event has not been yet registered.
 function getCallbacksListsForNamespace( source, eventName ) {
 	const eventNode = getEvents( source )[ eventName ];
 
-	/* istanbul ignore if: this check make sense but in code it does not occur. */
-	if ( !eventNode ) {
-		return [];
-	}
-
 	let callbacksLists = [ eventNode.callbacks ];
 
 	for ( let i = 0; i < eventNode.childEvents.length; i++ ) {

+ 22 - 1
packages/ckeditor5-utils/tests/emittermixin.js

@@ -331,7 +331,8 @@ describe( 'EmitterMixin', () => {
 		} );
 
 		it( 'should not fail with unknown events', () => {
-			emitter.off( 'test', () => {} );
+			emitter.off( 'foo', () => {} );
+			emitter.off( 'foo:bar', () => {} );
 		} );
 
 		it( 'should remove all entries for the same callback', () => {
@@ -531,6 +532,26 @@ describe( 'EmitterMixin', () => {
 			sinon.assert.notCalled( spyFoo );
 			sinon.assert.calledOnce( spyBar );
 		} );
+
+		it( 'should not fail with unknown events', () => {
+			listener.stopListening( emitter, 'foo', () => {} );
+			listener.stopListening( emitter, 'foo:bar', () => {} );
+			listener.stopListening( emitter, 'foo' );
+			listener.stopListening( emitter, 'foo:bar' );
+		} );
+
+		it( 'should not fail with unknown callbacks', () => {
+			const spy = sinon.spy();
+
+			listener.listenTo( emitter, 'foo', () => {
+				spy();
+			} );
+			listener.stopListening( emitter, 'foo', () => {} );
+
+			emitter.fire( 'foo' );
+
+			sinon.assert.calledOnce( spy );
+		} );
 	} );
 
 	describe( 'delegate', () => {