Skip to content

Commit

Permalink
test: switch alert tests to react testing library (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsprr committed Mar 19, 2024
1 parent 3904980 commit b36202a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 38 deletions.
38 changes: 0 additions & 38 deletions packages/react/__tests__/src/components/Alert/index.js

This file was deleted.

66 changes: 66 additions & 0 deletions packages/react/src/components/Alert/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import Alert from './';
import axe from '../../axe';

const defaults = { show: false, heading: <span>Default Alert</span> };

test('should return null when passed a falsey "show" prop', () => {
render(<Alert {...defaults}>Test Alert</Alert>);

expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});

test('should pass classNames through', () => {
render(
<Alert {...defaults} show className="baz">
Test Alert
</Alert>
);

expect(screen.queryByRole('dialog')).toHaveClass('Alert', 'baz');
});

test('should pass ref prop through', () => {
const ref = React.createRef<HTMLDivElement>();

render(
<Alert {...defaults} show dialogRef={ref}>
Test Alert
</Alert>
);

expect(ref.current).toBeInTheDocument();
});

test('should show modal when passed a truthy "show" prop', () => {
render(
<Alert {...defaults} show>
Test Alert
</Alert>
);

expect(screen.queryByRole('dialog')).toBeInTheDocument();
});

test('should return no axe violations', async () => {
const { container } = render(
<Alert {...defaults} show>
Hello!
</Alert>
);

const results = await axe(container);
expect(results).toHaveNoViolations();
});

test('should return no axe violations warning variant', async () => {
const { container } = render(
<Alert {...defaults} show variant="warning">
Hello!
</Alert>
);

const results = await axe(container);
expect(results).toHaveNoViolations();
});

0 comments on commit b36202a

Please sign in to comment.