mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #1069 from spicyj/gh-1028
Assert that event listeners are real functions
This commit is contained in:
@@ -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
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user