Skip to content

Commit

Permalink
refactor: test fix for Breadcrumb component
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 16, 2023
1 parent 60207fb commit 25c9c4a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Breadcrumb/Breadcrumb.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React from 'react';
import {render, screen, waitFor} from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import Breadcrumb from '.';

function setup(jsx) {
return {
user: userEvent.setup(),
...render(jsx),
};
}

const baseProps = {
links: [
{
Expand Down Expand Up @@ -50,15 +57,13 @@ describe('<Breadcrumb />', () => {

it('fires the passed in click handler', async () => {
const clickHandler = jest.fn();
render(<Breadcrumb {...baseProps} clickHandler={clickHandler}/>);
setup(<Breadcrumb {...baseProps} clickHandler={clickHandler} />);

const listItems = screen.queryAllByRole('listitem');
const links = screen.queryAllByRole('link');
expect(listItems.length).toBe(baseProps.links.length);
await waitFor(() => {
userEvent.click(links[0]);
expect(clickHandler).toHaveBeenCalled();
});
await userEvent.click(links[0]);
expect(clickHandler).toHaveBeenCalled();
});

it('renders in mobile view', () => {
Expand Down

0 comments on commit 25c9c4a

Please sign in to comment.