2017-02-17 02:59:55 +00:00
|
|
|
/**
|
2017-03-24 21:18:39 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2017-02-17 02:59:55 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-02-17 02:59:55 +00:00
|
|
|
*
|
2018-08-09 15:32:04 +00:00
|
|
|
* @flow strict-local
|
2017-06-13 05:32:58 +00:00
|
|
|
* @format
|
2017-02-17 02:59:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const FlatList = require('FlatList');
|
|
|
|
const React = require('react');
|
|
|
|
|
2017-02-28 10:09:09 +00:00
|
|
|
function renderMyListItem(info: {item: {title: string}, index: number}) {
|
|
|
|
return <span />;
|
2017-02-17 02:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-02-28 10:09:09 +00:00
|
|
|
testEverythingIsFine() {
|
2017-06-13 05:32:58 +00:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
title: 'Title Text',
|
|
|
|
key: 1,
|
|
|
|
},
|
|
|
|
];
|
2017-02-28 10:09:09 +00:00
|
|
|
return <FlatList renderItem={renderMyListItem} data={data} />;
|
|
|
|
},
|
|
|
|
|
|
|
|
testBadDataWithTypicalItem() {
|
2017-06-13 05:32:58 +00:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
// $FlowExpectedError - bad title type 6, should be string
|
|
|
|
title: 6,
|
|
|
|
key: 1,
|
|
|
|
},
|
|
|
|
];
|
2017-02-28 10:09:09 +00:00
|
|
|
return <FlatList renderItem={renderMyListItem} data={data} />;
|
2017-02-17 02:59:55 +00:00
|
|
|
},
|
|
|
|
|
2017-02-28 10:09:09 +00:00
|
|
|
testMissingFieldWithTypicalItem() {
|
2017-06-13 05:32:58 +00:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
key: 1,
|
|
|
|
},
|
|
|
|
];
|
2017-02-17 02:59:55 +00:00
|
|
|
// $FlowExpectedError - missing title
|
2017-02-28 10:09:09 +00:00
|
|
|
return <FlatList renderItem={renderMyListItem} data={data} />;
|
2017-02-17 02:59:55 +00:00
|
|
|
},
|
|
|
|
|
2017-02-28 10:09:09 +00:00
|
|
|
testGoodDataWithBadCustomRenderItemFunction() {
|
2017-06-13 05:32:58 +00:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
widget: 6,
|
|
|
|
key: 1,
|
|
|
|
},
|
|
|
|
];
|
2017-02-17 02:59:55 +00:00
|
|
|
return (
|
|
|
|
<FlatList
|
2017-09-27 06:33:30 +00:00
|
|
|
renderItem={info => (
|
2017-07-10 22:22:19 +00:00
|
|
|
<span>
|
|
|
|
{
|
|
|
|
// $FlowExpectedError - bad widgetCount type 6, should be Object
|
|
|
|
info.item.widget.missingProp
|
|
|
|
}
|
2017-09-27 06:33:30 +00:00
|
|
|
</span>
|
|
|
|
)}
|
2017-02-17 02:59:55 +00:00
|
|
|
data={data}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2017-02-28 10:09:09 +00:00
|
|
|
testBadRenderItemFunction() {
|
2017-06-13 05:32:58 +00:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
title: 'foo',
|
|
|
|
key: 1,
|
|
|
|
},
|
|
|
|
];
|
2017-02-28 10:09:09 +00:00
|
|
|
return [
|
|
|
|
// $FlowExpectedError - title should be inside `item`
|
2017-06-13 05:32:58 +00:00
|
|
|
<FlatList renderItem={(info: {title: string}) => <span />} data={data} />,
|
|
|
|
<FlatList
|
|
|
|
// $FlowExpectedError - bad index type string, should be number
|
|
|
|
renderItem={(info: {item: any, index: string}) => <span />}
|
|
|
|
data={data}
|
|
|
|
/>,
|
|
|
|
<FlatList
|
|
|
|
// $FlowExpectedError - bad title type number, should be string
|
|
|
|
renderItem={(info: {item: {title: number}}) => <span />}
|
|
|
|
data={data}
|
|
|
|
/>,
|
2017-02-28 10:09:09 +00:00
|
|
|
// EverythingIsFine
|
2017-06-13 05:32:58 +00:00
|
|
|
<FlatList
|
|
|
|
renderItem={(info: {item: {title: string}}) => <span />}
|
|
|
|
data={data}
|
|
|
|
/>,
|
2017-02-28 10:09:09 +00:00
|
|
|
];
|
2017-02-17 02:59:55 +00:00
|
|
|
},
|
|
|
|
|
2017-02-28 10:09:09 +00:00
|
|
|
testOtherBadProps() {
|
|
|
|
return [
|
|
|
|
// $FlowExpectedError - bad numColumns type "lots"
|
|
|
|
<FlatList renderItem={renderMyListItem} data={[]} numColumns="lots" />,
|
|
|
|
// $FlowExpectedError - bad windowSize type "big"
|
|
|
|
<FlatList renderItem={renderMyListItem} data={[]} windowSize="big" />,
|
|
|
|
// $FlowExpectedError - missing `data` prop
|
|
|
|
<FlatList renderItem={renderMyListItem} />,
|
|
|
|
];
|
2017-02-17 02:59:55 +00:00
|
|
|
},
|
|
|
|
};
|