mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Test that fabric renderer sends diffs (#12075)
This commit is contained in:
@@ -72,21 +72,21 @@ const RCTFabricUIManager = {
|
||||
}),
|
||||
cloneNodeWithNewProps: jest.fn(function cloneNodeWithNewProps(
|
||||
node,
|
||||
newProps,
|
||||
newPropsDiff,
|
||||
) {
|
||||
return {
|
||||
reactTag: node.reactTag,
|
||||
viewName: node.viewName,
|
||||
props: newProps,
|
||||
props: {...node.props, ...newPropsDiff},
|
||||
children: node.children,
|
||||
};
|
||||
}),
|
||||
cloneNodeWithNewChildrenAndProps: jest.fn(
|
||||
function cloneNodeWithNewChildrenAndProps(node, newProps) {
|
||||
function cloneNodeWithNewChildrenAndProps(node, newPropsDiff) {
|
||||
return {
|
||||
reactTag: node.reactTag,
|
||||
viewName: node.viewName,
|
||||
props: newProps,
|
||||
props: {...node.props, ...newPropsDiff},
|
||||
children: [],
|
||||
};
|
||||
},
|
||||
|
||||
@@ -109,6 +109,48 @@ describe('ReactFabric', () => {
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('should only pass props diffs to FabricUIManager.cloneNode', () => {
|
||||
const View = createReactNativeComponentClass('View', () => ({
|
||||
validAttributes: {foo: true, bar: true},
|
||||
uiViewClassName: 'View',
|
||||
}));
|
||||
|
||||
ReactFabric.render(
|
||||
<View foo="a" bar="a">
|
||||
1
|
||||
</View>,
|
||||
11,
|
||||
);
|
||||
expect(FabricUIManager.cloneNode).not.toBeCalled();
|
||||
expect(FabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
|
||||
expect(FabricUIManager.cloneNodeWithNewProps).not.toBeCalled();
|
||||
expect(FabricUIManager.cloneNodeWithNewChildrenAndProps).not.toBeCalled();
|
||||
|
||||
ReactFabric.render(
|
||||
<View foo="a" bar="b">
|
||||
1
|
||||
</View>,
|
||||
11,
|
||||
);
|
||||
expect(FabricUIManager.cloneNodeWithNewProps.mock.calls[0][1]).toEqual({
|
||||
bar: 'b',
|
||||
});
|
||||
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
|
||||
|
||||
ReactFabric.render(
|
||||
<View foo="b" bar="b">
|
||||
2
|
||||
</View>,
|
||||
11,
|
||||
);
|
||||
expect(
|
||||
FabricUIManager.cloneNodeWithNewChildrenAndProps.mock.calls[0][1],
|
||||
).toEqual({
|
||||
foo: 'b',
|
||||
});
|
||||
expect(FabricUIManager.__dumpHierarchyForJestTestsOnly()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should not call UIManager.updateView from setNativeProps for properties that have not changed', () => {
|
||||
const View = createReactNativeComponentClass('View', () => ({
|
||||
validAttributes: {foo: true},
|
||||
|
||||
+12
@@ -49,3 +49,15 @@ exports[`ReactFabric renders and reorders children 2`] = `
|
||||
View {\\"title\\":\\"z\\"}
|
||||
View {\\"title\\":\\"y\\"}"
|
||||
`;
|
||||
|
||||
exports[`ReactFabric should only pass props diffs to FabricUIManager.cloneNode 1`] = `
|
||||
"11
|
||||
View {\\"foo\\":\\"a\\",\\"bar\\":\\"b\\"}
|
||||
RCTRawText {\\"text\\":\\"1\\"}"
|
||||
`;
|
||||
|
||||
exports[`ReactFabric should only pass props diffs to FabricUIManager.cloneNode 2`] = `
|
||||
"11
|
||||
View {\\"foo\\":\\"b\\",\\"bar\\":\\"b\\"}
|
||||
RCTRawText {\\"text\\":\\"2\\"}"
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user