@samitouri / QOS-React / commits / 6b8db0e111

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

Christoph Pojer committed Jun 13, 2016 at 22:50 UTC 6b8db0e1113581602199d7c6cf7a284a9654ef1a
2 files changed +21 -1
src/renderers/testing/ReactTestRenderer.js
+5 -1
@@ -74,11 +74,15 @@ ReactTestComponent.prototype.toJSON = function() {
74 childrenJSON.push(json);
75 }
76 }
77 - return {
77 + var object = {
78 type: this._currentElement.type,
79 props: props,
80 children: childrenJSON.length ? childrenJSON : null,
81 };
82 + Object.defineProperty(object, '$$typeof', {
83 + value: Symbol.for('react.test.json'),
84 + });
85 + return object;
86 };
87 Object.assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
88
src/renderers/testing/__tests__/ReactTestRenderer-test.js
+16
@@ -28,6 +28,22 @@ describe('ReactTestRenderer', function() {
28 });
29 });
30
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 +
47 it('renders some basics with an update', function() {
48 var renders = 0;
49 var Component = React.createClass({