Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/classic/class/ReactClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@ var typeDeprecationDescriptor = {
displayName,
displayName
);
Object.defineProperty(this, 'type', {
value: this
});
return this;
}
};
Expand Down
15 changes: 15 additions & 0 deletions src/classic/class/__tests__/ReactClass-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down