Skip to content

Commit 705386f

Browse files
committed
ReactTestRenderer: inline component creation
1 parent 5c28043 commit 705386f

File tree

2 files changed

+29
-51
lines changed

2 files changed

+29
-51
lines changed

src/renderers/testing/fiber/ReactTestFiberComponent.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/renderers/testing/fiber/ReactTestFiberRenderer.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
var invariant = require('invariant');
1717
var ReactFiberReconciler = require('ReactFiberReconciler');
18-
var ReactTestFiberComponent = require('ReactTestFiberComponent');
1918

2019
import type { ReactElement } from 'ReactElementType';
2120
import type { ReactInstance } from 'ReactInstanceType';
@@ -27,11 +26,35 @@ type ReactTestRendererJSON = {
2726
$$typeof?: any
2827
}
2928

30-
var {
31-
createElement,
32-
setInitialProperties,
33-
updateProperties,
34-
} = ReactTestFiberComponent;
29+
let instanceCounter = 0;
30+
var createElement = (type, rawProps, rootContainerInstance) => {
31+
const {children, ...props} = rawProps;
32+
var inst = {
33+
id: instanceCounter++,
34+
type: type,
35+
children: typeof children === 'undefined' ? null : Array.isArray(children) ? children : [children],
36+
props: props,
37+
};
38+
// Hide from unit tests
39+
Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false });
40+
Object.defineProperty(inst, '$$typeof', {
41+
value: Symbol.for('react.test.json'),
42+
});
43+
// todo: something like this?
44+
// const mockInst = rootContainerInstance.createNodeMock(inst);
45+
return inst;
46+
};
47+
48+
var setInitialProperties = () => {
49+
throw new Error('TODO: setInitialProperties');
50+
};
51+
52+
var updateProperties = (element, type, oldProps, newProps) => {
53+
const {children, ...props} = newProps;
54+
element.type = type;
55+
element.props = props;
56+
element.children = typeof children === 'undefined' ? null : Array.isArray(children) ? children : [children];
57+
};
3558

3659
var TestRenderer = ReactFiberReconciler({
3760
getRootHostContext(rootContainerInstance : Container) : HostContext {

0 commit comments

Comments
 (0)