Skip to content

Commit 243be87

Browse files
cpojerzpao
authored andcommitted
Add symbol to identify a ReactTestComponent instance. (facebook#7035)
(cherry picked from commit 6b8db0e)
1 parent eab4ffa commit 243be87

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/renderers/testing/ReactTestRenderer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ ReactTestComponent.prototype.toJSON = function() {
7474
childrenJSON.push(json);
7575
}
7676
}
77-
return {
77+
var object = {
7878
type: this._currentElement.type,
7979
props: props,
8080
children: childrenJSON.length ? childrenJSON : null,
8181
};
82+
Object.defineProperty(object, '$$typeof', {
83+
value: Symbol.for('react.test.json'),
84+
});
85+
return object;
8286
};
8387
Object.assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
8488

src/renderers/testing/__tests__/ReactTestRenderer-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ describe('ReactTestRenderer', function() {
2828
});
2929
});
3030

31+
it('exposes a type flag', function() {
32+
function Link() {
33+
return <a role="link" />;
34+
}
35+
var renderer = ReactTestRenderer.create(<Link />);
36+
var object = renderer.toJSON();
37+
expect(object.$$typeof).toBe(Symbol.for('react.test.json'));
38+
39+
// $$typeof should not be enumerable.
40+
for (var key in object) {
41+
if (Object.prototype.hasOwnProperty.call(object, key)) {
42+
expect(key).not.toBe('$$typeof');
43+
}
44+
}
45+
});
46+
3147
it('renders some basics with an update', function() {
3248
var renders = 0;
3349
var Component = React.createClass({

0 commit comments

Comments
 (0)