Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/171312
Change subject: EventEmitter: Simplify #validateMethod and increase test coverage ...................................................................... EventEmitter: Simplify #validateMethod and increase test coverage * Add test to verify that validateMethod works properly for undefined or non-function values. * Simplify implementation by removing the explicit undefined check (undefined properties yield the undefined value in javascript). Change-Id: I6569f8a65d29a75bd451fa473ac8c95fa0af7eda --- M src/EventEmitter.js M tests/unit/EventEmitter.test.js 2 files changed, 15 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/oojs/core refs/changes/12/171312/1 diff --git a/src/EventEmitter.js b/src/EventEmitter.js index 0130d3e..12a90e8 100644 --- a/src/EventEmitter.js +++ b/src/EventEmitter.js @@ -41,11 +41,6 @@ if ( context === undefined || context === null ) { throw new Error( 'Method name "' + method + '" has no context.' ); } - if ( !( method in context ) ) { - // Technically the method does not need to exist yet: it could be - // added before call time. But this probably signals a typo. - throw new Error( 'Method not found: "' + method + '"' ); - } if ( typeof context[method] !== 'function' ) { // Technically the property could be replaced by a function before // call time. But this probably signals a typo. diff --git a/tests/unit/EventEmitter.test.js b/tests/unit/EventEmitter.test.js index 711475c..89b87ef 100644 --- a/tests/unit/EventEmitter.test.js +++ b/tests/unit/EventEmitter.test.js @@ -148,7 +148,7 @@ assert.ok( true, 'Unbinding an unknown callback for event named "hasOwnProperty"' ); } ); - QUnit.test( 'connect', 3, function ( assert ) { + QUnit.test( 'connect', 5, function ( assert ) { var data1, host, ee = new oo.EventEmitter(); @@ -160,7 +160,8 @@ }, barbara: function ( a ) { assert.strictEqual( a, data1, 'Connect takes variadic list of arguments to be passed' ); - } + }, + bazoon: [ 'not', 'a', 'function' ] }; ee.connect( host, { @@ -174,6 +175,18 @@ ee.emit( 'foo' ); ee.emit( 'bar' ); ee.emit( 'quux' ); + + assert.throws( function () { + ee.connect( host, { + baz: 'onBaz' + } ); + }, 'Connecting to unknown method' ); + + assert.throws( function () { + ee.connect( host, { + baz: 'bazoon' + } ); + }, 'Connecting to invalid method' ); } ); QUnit.test( 'disconnect( host )', 1, function ( assert ) { -- To view, visit https://gerrit.wikimedia.org/r/171312 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6569f8a65d29a75bd451fa473ac8c95fa0af7eda Gerrit-PatchSet: 1 Gerrit-Project: oojs/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits