mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add symbol to identify a ReactTestComponent instance. (#7035)
(cherry picked from commit 6b8db0e111)
This commit is contained in:
committed by
Paul O’Shannessy
parent
eab4ffa721
commit
243be87c6d
@@ -74,11 +74,15 @@ ReactTestComponent.prototype.toJSON = function() {
|
||||
childrenJSON.push(json);
|
||||
}
|
||||
}
|
||||
return {
|
||||
var object = {
|
||||
type: this._currentElement.type,
|
||||
props: props,
|
||||
children: childrenJSON.length ? childrenJSON : null,
|
||||
};
|
||||
Object.defineProperty(object, '$$typeof', {
|
||||
value: Symbol.for('react.test.json'),
|
||||
});
|
||||
return object;
|
||||
};
|
||||
Object.assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
|
||||
|
||||
|
||||
@@ -28,6 +28,22 @@ describe('ReactTestRenderer', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('exposes a type flag', function() {
|
||||
function Link() {
|
||||
return <a role="link" />;
|
||||
}
|
||||
var renderer = ReactTestRenderer.create(<Link />);
|
||||
var object = renderer.toJSON();
|
||||
expect(object.$$typeof).toBe(Symbol.for('react.test.json'));
|
||||
|
||||
// $$typeof should not be enumerable.
|
||||
for (var key in object) {
|
||||
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
||||
expect(key).not.toBe('$$typeof');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('renders some basics with an update', function() {
|
||||
var renders = 0;
|
||||
var Component = React.createClass({
|
||||
|
||||
Reference in New Issue
Block a user