Skip to content

Commit

Permalink
test: add tests for first, last props and ReactNode rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
metacode22 committed Sep 1, 2024
1 parent 67851af commit 8666ba4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/react/react/src/components/Separated/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,58 @@ describe('Separated', () => {

expect(screen.queryByTestId(/separator/)).not.toBeInTheDocument();
});

it('should render separator at the beginning when first prop is true', () => {
const CHILDREN_COUNT = 10;
const separator = <span data-testid="separator" />;
const children = Array.from({ length: CHILDREN_COUNT }, (_, i) => (
<div key={i} data-testid={i}>
container_{i}
</div>
));

const { container } = render(
<Separated with={separator} first>
{children}
</Separated>
);

expect(container.firstChild).toHaveAttribute('data-testid', 'separator');
expect(screen.getAllByText(/container/)).toHaveLength(CHILDREN_COUNT);
expect(screen.getAllByTestId(/separator/)).toHaveLength(CHILDREN_COUNT);
});

it('should render separator at the end when last prop is true', () => {
const CHILDREN_COUNT = 10;
const separator = <span data-testid="separator" />;
const children = Array.from({ length: CHILDREN_COUNT }, (_, i) => (
<div key={i} data-testid={i}>
container_{i}
</div>
));

const { container } = render(
<Separated with={separator} last>
{children}
</Separated>
);

expect(container.lastChild).toHaveAttribute('data-testid', 'separator');
expect(screen.getAllByText(/container/)).toHaveLength(CHILDREN_COUNT);
expect(screen.getAllByTestId(/separator/)).toHaveLength(CHILDREN_COUNT);
});

it('should render all ReactNode types', () => {
const separator = <span data-testid="separator" />;

render(
<Separated with={separator}>
string
{0}
string
</Separated>
);

expect(screen.getAllByTestId(/separator/)).toHaveLength(2);
});
});

0 comments on commit 8666ba4

Please sign in to comment.