Merge pull request #1069 from spicyj/gh-1028

Assert that event listeners are real functions
This commit is contained in:
Pete Hunt
2014-02-13 10:48:20 -08:00
3 changed files with 17 additions and 1 deletions
@@ -19,6 +19,8 @@
"use strict";
var ReactPropTypes = require('ReactPropTypes');
var invariant = require('invariant');
var hasReadOnlyValue = {
@@ -110,7 +112,8 @@ var LinkedValueUtils = {
);
}
}
}
},
onChange: ReactPropTypes.func
}
},
+5
View File
@@ -155,6 +155,11 @@ var EventPluginHub = {
ExecutionEnvironment.canUseDOM,
'Cannot call putListener() in a non-DOM environment.'
);
invariant(
!listener || typeof listener === 'function',
'Expected %s listener to be a function, instead got type %s',
registrationName, typeof listener
);
if (__DEV__) {
// IE8 has no API for event capturing and the `onScroll` event doesn't
@@ -42,4 +42,12 @@ describe('EventPluginHub', function() {
);
});
it("should prevent non-function listeners", function() {
expect(function() {
EventPluginHub.putListener(1, 'onClick', 'not a function');
}).toThrow(
'Invariant Violation: Expected onClick listener to be a function, ' +
'instead got type string'
);
});
});