Skip to content

Commit 9298633

Browse files
authored
Fix: issue with order 0 returning null (#75)
* fix: value being consider null if it was 0 * test: update tests * refactor: added more coverage
1 parent 894d9f5 commit 9298633

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/helpers/CSSProperty/CSSProperty.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export const getPropertyValue = (props, breakpoint, property) => {
1313

1414
if (has(props, `${propertySlug}`)) {
1515
if (isObject(props[propertySlug])) {
16-
return props[propertySlug][breakpoint] || null;
16+
const value = props[propertySlug][breakpoint];
17+
if (value === 0) {
18+
return value.toString();
19+
}
20+
21+
return value || null;
1722
}
1823

1924
if (breakpoint === sortBreakpoints(ThemeBreakpoints)[0]) {
@@ -27,7 +32,6 @@ export const getPropertyValue = (props, breakpoint, property) => {
2732

2833
const CSSProperty = (props, breakpoint, property) => {
2934
const value = getPropertyValue(props, breakpoint, property);
30-
3135
return isNull(value) ? null : css`
3236
${property}: ${value};
3337
`;

src/helpers/CSSProperty/CSSProperty.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ describe('getPropertyValue', () => {
3131
const mockProps = { alignSelf: { sm: 'center' } };
3232
expect(getPropertyValue(mockProps, 'lg', 'align-self')).toEqual(null);
3333
});
34+
35+
test('should generate value when it is 0 (falsy)', () => {
36+
const mockProps = { order: { sm: 0 } };
37+
expect(getPropertyValue(mockProps, 'sm', 'order')).toEqual('0');
38+
});
39+
40+
test('should not generate value when it is null (falsy)', () => {
41+
const mockProps = { order: { sm: false } };
42+
expect(getPropertyValue(mockProps, 'sm', 'order')).toEqual(null);
43+
});
3444
});
3545

3646
describe('CSSProperty', () => {
@@ -48,4 +58,9 @@ describe('CSSProperty', () => {
4858
const mockProps = { alignSelf: { sm: 'center' } };
4959
expect(CSSProperty(mockProps, 'sm', 'align-self').join('')).toContain('align-self: center');
5060
});
61+
62+
test('should generte order even when 0', () => {
63+
const mockProps = { order: { sm: 0 } };
64+
expect(CSSProperty(mockProps, 'sm', 'order').join('')).toContain('order: 0');
65+
});
5166
});

0 commit comments

Comments
 (0)