SectionList-flowtest.js
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/
'use strict';
const React = require('react');
const SectionList = require('SectionList');
function renderMyListItem(info: {item: {title: string}, index: number}) {
return <span />;
}
const renderMyHeader = ({section}: {section: {fooNumber: number} & Object}) => (
<span />
);
module.exports = {
testGoodDataWithGoodItem() {
const sections = [
{
key: 'a',
data: [
{
title: 'foo',
key: 1,
},
],
},
];
return <SectionList renderItem={renderMyListItem} sections={sections} />;
},
testBadRenderItemFunction() {
const sections = [
{
key: 'a',
data: [
{
title: 'foo',
key: 1,
},
],
},
];
return [
// $FlowExpectedError - title should be inside `item`
<SectionList
renderItem={(info: {title: string}) => <span />}
sections={sections}
/>,
<SectionList
// $FlowExpectedError - bad index type string, should be number
renderItem={(info: {index: string}) => <span />}
sections={sections}
/>,
// EverythingIsFine
<SectionList
renderItem={(info: {item: {title: string}}) => <span />}
sections={sections}
/>,
];
},
testBadInheritedDefaultProp(): React.Element<*> {
const sections = [];
return (
<SectionList
renderItem={renderMyListItem}
sections={sections}
// $FlowExpectedError - bad windowSize type "big"
windowSize="big"
/>
);
},
testMissingData(): React.Element<*> {
// $FlowExpectedError - missing `sections` prop
return <SectionList renderItem={renderMyListItem} />;
},
testBadSectionsShape(): React.Element<*> {
const sections = [
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.63 was deployed. To see the error delete this
* comment and run Flow. */
{
key: 'a',
items: [
{
title: 'foo',
key: 1,
},
],
},
];
// $FlowExpectedError - section missing `data` field
return <SectionList renderItem={renderMyListItem} sections={sections} />;
},
testBadSectionsMetadata(): React.Element<*> {
const sections = [
{
key: 'a',
// $FlowExpectedError - section has bad meta data `fooNumber` field of type string
fooNumber: 'string',
data: [
{
title: 'foo',
key: 1,
},
],
},
];
return (
<SectionList
renderSectionHeader={renderMyHeader}
renderItem={renderMyListItem}
sections={sections}
/>
);
},
};