Skip to content

Commit

Permalink
test: update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Dec 16, 2024
1 parent 2ae234d commit c5ca0a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Breadcrumb/Breadcrumb.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ describe('<Breadcrumb />', () => {
expect(screen.getAllByRole('presentation').length).toBe(2);
});

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

const listItems = screen.queryAllByRole('listitem');
const links = screen.queryAllByRole('link');
expect(listItems.length).toBe(baseProps.links.length);

userEvent.click(links[0]);
await user.click(links[0]);
expect(clickHandler).toHaveBeenCalled();
});

Expand Down
10 changes: 6 additions & 4 deletions src/Button/deprecated/Button.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ describe('<Button />', () => {
expect(button).toBeInTheDocument();
});

it('puts focus on button on click', () => {
it('puts focus on button on click', async () => {
const user = userEvent.setup();
const { getByText } = render(<Button {...defaultProps} />);
const button = getByText(defaultProps.label);

expect(button).not.toHaveFocus();
userEvent.click(button);
await user.click(button);
expect(button).toHaveFocus();
});

it('calls onClick prop on click', () => {
it('calls onClick prop on click', async () => {
const user = userEvent.setup();
const onClickSpy = jest.fn();
const { getByText } = render(<Button {...defaultProps} onClick={onClickSpy} />);
const button = getByText(defaultProps.label);

userEvent.click(button);
await user.click(button);
expect(onClickSpy).toHaveBeenCalledTimes(1);
});
});
10 changes: 6 additions & 4 deletions src/Card/CardCarousel/tests/CardCarouselControls.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,29 @@ describe('<CardCarouselControls />', () => {
expect(tree).toMatchSnapshot();
});

it('handles scroll to previous click', () => {
it('handles scroll to previous click', async () => {
const user = userEvent.setup();
const contextValue = {
...defaultCardCarouselContextValue,
isScrolledToStart: false,
};
render((
<CardCarouselControlsWrapper cardCarouselContextValue={contextValue} />
));
userEvent.click(screen.getByLabelText('Scroll to previous'));
await user.click(screen.getByLabelText('Scroll to previous'));
expect(mockScrollToPrevious).toHaveBeenCalledTimes(1);
});

it('handles scroll to next click', () => {
it('handles scroll to next click', async () => {
const user = userEvent.setup();
const contextValue = {
...defaultCardCarouselContextValue,
isScrolledToEnd: false,
};
render((
<CardCarouselControlsWrapper cardCarouselContextValue={contextValue} />
));
userEvent.click(screen.getByLabelText('Scroll to next'));
await user.click(screen.getByLabelText('Scroll to next'));
expect(mockScrollToNext).toHaveBeenCalledTimes(1);
});
});

0 comments on commit c5ca0a5

Please sign in to comment.