mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
When proxying statics functions, copy properties
Test Plan: jest
This commit is contained in:
@@ -93,7 +93,15 @@ function proxyStaticMethods(target, source) {
|
||||
if (source.hasOwnProperty(key)) {
|
||||
var value = source[key];
|
||||
if (typeof value === 'function') {
|
||||
target[key] = value.bind(source);
|
||||
var bound = value.bind(source);
|
||||
// Copy any properties defined on the function, such as `isRequired` on
|
||||
// a PropTypes validator. (mergeInto refuses to work on functions.)
|
||||
for (var k in value) {
|
||||
if (value.hasOwnProperty(k)) {
|
||||
bound[k] = value[k];
|
||||
}
|
||||
}
|
||||
target[key] = bound;
|
||||
} else {
|
||||
target[key] = value;
|
||||
}
|
||||
|
||||
@@ -63,4 +63,16 @@ describe('ReactDescriptor', function() {
|
||||
expect(test.foo).toHaveBeenCalledWith(a, b, c);
|
||||
});
|
||||
|
||||
it('allows the use of PropTypes validators in statics', function() {
|
||||
var Component = React.createClass({
|
||||
render: () => null,
|
||||
statics: {
|
||||
specialType: React.PropTypes.shape({monkey: React.PropTypes.any})
|
||||
}
|
||||
});
|
||||
|
||||
expect(typeof Component.specialType).toBe("function");
|
||||
expect(typeof Component.specialType.isRequired).toBe("function");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user