Add symbol to identify a ReactTestComponent instance. (#7035)

(cherry picked from commit 6b8db0e111)
This commit is contained in:
Christoph Pojer
2016-06-14 15:50:39 -07:00
committed by Paul O’Shannessy
parent eab4ffa721
commit 243be87c6d
2 changed files with 21 additions and 1 deletions
+5 -1
View File
@@ -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({