Skip to content

Commit 0a53ea5

Browse files
committed
Add memoized React component test
1 parent 145918a commit 0a53ea5

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

test/__snapshots__/propType.test.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,38 @@ Object {
5050
}
5151
`;
5252

53+
exports[`Connected Components React Plugin - PropTypes ComponentWithMemoization.jsx snippet creation 1`] = `
54+
Object {
55+
"description": "Component description.",
56+
"lang": "jsx",
57+
"snippet": "<MyComponent
58+
optionalArray={array}
59+
optionalBool={bool}
60+
optionalFunc={func}
61+
optionalNumber={number}
62+
optionalObject={object}
63+
optionalString={string}
64+
optionalSymbol={symbol}
65+
optionalNode={node}
66+
optionalElement={element}
67+
optionalElementType={elementType}
68+
optionalFoo={instanceOf(Foo)}
69+
optionalEnum={enum}
70+
optionalUnion={union[string|number|instanceOf(Foo)}]
71+
optionalArrayOf={arrayOf[number]}
72+
optionalObjectOf={objectOf[number]}
73+
optionalObjectWithShape={shape}
74+
optionalObjectWithStrictShape={exact}
75+
requiredFunc={func}
76+
requiredAny={any}
77+
customProp={() => {}}
78+
customArrayProp={arrayOf[custom]}
79+
customObjectOfProp={objectOf[custom]}>
80+
{children}
81+
</MyComponent>",
82+
}
83+
`;
84+
5385
exports[`Connected Components React Plugin - PropTypes ComponentWithProps.jsx snippet creation 1`] = `
5486
Object {
5587
"description": "Component description.",

test/propType.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ describe("Connected Components React Plugin - PropTypes", () => {
5353
expect(componentCode).toMatchSnapshot();
5454
});
5555

56-
test.skip("FlowType.jsx snippet creation", async () => {
56+
test("ComponentWithMemoization.jsx snippet creation", async () => {
5757
const processor = new Plugin();
5858

5959
const componentCode = await processor.process(
6060
{
61-
path: "test/samples/TSType.tsx",
61+
path: "test/samples/ComponentWithMemoization.jsx",
6262
zeplinNames: []
6363
}
6464
);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import PropTypes from "prop-types";
2+
3+
class Foo {}
4+
5+
/** Component description. */
6+
class MyComponent extends React.Component {
7+
render() {
8+
return "";
9+
}
10+
}
11+
// All examples of propTypes listed official documentation
12+
MyComponent.propTypes = {
13+
children: PropTypes.element.isRequired,
14+
optionalArray: PropTypes.array,
15+
optionalBool: PropTypes.bool,
16+
optionalFunc: PropTypes.func,
17+
optionalNumber: PropTypes.number,
18+
optionalObject: PropTypes.object,
19+
optionalString: PropTypes.string,
20+
optionalSymbol: PropTypes.symbol,
21+
optionalNode: PropTypes.node,
22+
optionalElement: PropTypes.element,
23+
optionalElementType: PropTypes.elementType,
24+
optionalFoo: PropTypes.instanceOf(Foo),
25+
optionalEnum: PropTypes.oneOf(["News", "Photos"]),
26+
optionalUnion: PropTypes.oneOfType([
27+
PropTypes.string,
28+
PropTypes.number,
29+
PropTypes.instanceOf(Foo)
30+
]),
31+
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
32+
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
33+
optionalObjectWithShape: PropTypes.shape({
34+
color: PropTypes.string,
35+
fontSize: PropTypes.number
36+
}),
37+
optionalObjectWithStrictShape: PropTypes.exact({
38+
name: PropTypes.string,
39+
quantity: PropTypes.number
40+
}),
41+
requiredFunc: PropTypes.func.isRequired,
42+
requiredAny: PropTypes.any.isRequired,
43+
customProp: () => {},
44+
customArrayProp: PropTypes.arrayOf(() => {}),
45+
customObjectOfProp: PropTypes.objectOf(() => {})
46+
};
47+
48+
function someKindOfComparator(prevProps, nextProps) {
49+
}
50+
51+
export default React.memo(MyComponent, someKindOfComparator);

0 commit comments

Comments
 (0)