Skip to content

Commit 65d8d76

Browse files
author
Igor Canedo
committed
handling getItemType object problem
1 parent 3508ddc commit 65d8d76

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2017, Globo.com (https://github.com/globocom)
3+
*
4+
* License: MIT
5+
*/
6+
7+
/* eslint-env jest */
8+
9+
import getItemType from '../../../src/helpers/getItemType';
10+
11+
it('returns empty string if object doesnt have style attribute', () => {
12+
const mock = {};
13+
const result = getItemType(mock);
14+
expect(result).toEqual('');
15+
});

src/helpers/getItemType.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2017, Globo.com (https://github.com/globocom)
3+
*
4+
* License: MIT
5+
*/
6+
7+
// @flow
8+
9+
const getItemType = (item: Object): string => {
10+
if (item.style) {
11+
if (Array.isArray(item.style)) {
12+
return item.style.map((i: string): string => i.toLowerCase());
13+
}
14+
return item.style.toLowerCase();
15+
}
16+
return '';
17+
};
18+
19+
export default getItemType;

src/loadAttributes.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import {
1515
import TextStyled from './components/TextStyled';
1616
import generateKey from './utils/generateKey';
1717
import flatAttributesList from './flatAttributesList';
18-
19-
const getItemType = (item: Object): string => {
20-
if (Array.isArray(item.style)) {
21-
return item.style.map((i: string): string => i.toLowerCase());
22-
}
23-
return item.style.toLowerCase();
24-
};
18+
import getItemType from './helpers/getItemType';
2519

2620
const getItemOnPress = (item: Object, entityMap: Object, navigate: Function) => {
2721
if (item.key !== undefined) {

0 commit comments

Comments
 (0)