Skip to content

Commit

Permalink
fix: badge should render children 0 value (#6981)
Browse files Browse the repository at this point in the history
When passing 0 in as child, the 0 was not rendred. Fixed the badge
component and added tests.


![image](https://github.com/Unleash/unleash/assets/964450/d681b70c-5d55-4818-86ea-7d05fa86c7b3)
  • Loading branch information
sjaanus authored May 6, 2024
1 parent 233b882 commit d698ecc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions frontend/src/component/common/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { screen } from '@testing-library/react';
import { Badge } from './Badge';
import { render } from '../../../utils/testRenderer';

test('Badge should render text', async () => {
render(<Badge color='success'>Predefined</Badge>);

const result = await screen.findByText('Predefined');
expect(result).toBeInTheDocument();
});

test('Badge should children number 0', async () => {
render(<Badge color='success'>{0}</Badge>);

const result = await screen.findByText('0');
expect(result).toBeInTheDocument();
});
6 changes: 5 additions & 1 deletion frontend/src/component/common/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ export const Badge: FC<IBadgeProps> = forwardRef(
show={BadgeIcon(color, icon!)}
/>
<ConditionallyRender
condition={Boolean(children)}
condition={
children !== null &&
children !== undefined &&
children !== ''
}
show={<div>{children}</div>}
/>
<ConditionallyRender
Expand Down

0 comments on commit d698ecc

Please sign in to comment.