Test that fabric renderer sends diffs (#12075)

This commit is contained in:
Sebastian Markbåge
2018-01-22 22:29:43 -08:00
committed by GitHub
parent 04d8fecc4a
commit 4d65408938
3 changed files with 58 additions and 4 deletions
@@ -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},
@@ -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\\"}"
`;