-
-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathAlert.test.tsx
More file actions
32 lines (24 loc) · 1.02 KB
/
Alert.test.tsx
File metadata and controls
32 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { fireEvent, render } from '@testing-library/react';
import createSnapshotTest from 'test-utils/createSnapshotTest';
import { ALERT_CLOSE_BUTTON } from 'common/constants/testIDs';
import Alert from '../Alert';
describe('Alert', () => {
it('should render error alert with required props', () => {
createSnapshotTest(<Alert type="error">Error Alert JSX or Text</Alert>);
});
it('should call close handler when close alert button clicked', () => {
const onCloseMock = vi.fn();
const { queryByTestId } = render(
<Alert type="success" onClose={onCloseMock}>
Success Alert JSX or Text
</Alert>,
);
expect(onCloseMock).toHaveBeenCalledTimes(0);
fireEvent.click(queryByTestId(ALERT_CLOSE_BUTTON)!);
expect(onCloseMock).toHaveBeenCalledTimes(1);
});
it('should NOT render button if close handler not provided', () => {
const { queryByTestId } = render(<Alert type="warning">Warning Alert JSX or Text</Alert>);
expect(queryByTestId(ALERT_CLOSE_BUTTON)).toBeNull();
});
});