Warn only once for each class when accessing .type

Currently it is a bit too spammy.
This commit is contained in:
Sebastian Markbage
2015-02-05 12:32:15 -08:00
parent c7e4f55eb0
commit 140d9b4192
2 changed files with 18 additions and 0 deletions
+3
View File
@@ -714,6 +714,9 @@ var typeDeprecationDescriptor = {
displayName,
displayName
);
Object.defineProperty(this, 'type', {
value: this
});
return this;
}
};
@@ -50,12 +50,27 @@ describe('ReactClass-spec', function() {
return <div />;
}
});
var SecondTestComponent = React.createClass({
render: function() {
return <div />;
}
});
expect(TestComponent.type).toBe(TestComponent);
expect(console.warn.argsForCall.length).toBe(1);
expect(console.warn.argsForCall[0][0]).toBe(
'Warning: TestComponent.type is deprecated. Use TestComponent ' +
'directly to access the class.'
);
// Warn once per class
expect(SecondTestComponent.type).toBe(SecondTestComponent);
expect(console.warn.argsForCall.length).toBe(2);
expect(console.warn.argsForCall[1][0]).toBe(
'Warning: SecondTestComponent.type is deprecated. Use ' +
'SecondTestComponent directly to access the class.'
);
// Not again
expect(TestComponent.type).toBe(TestComponent);
expect(console.warn.argsForCall.length).toBe(2);
});
it('should copy prop types onto the Constructor', function() {