Skip to content

Commit 5ac357b

Browse files
authored
Add tests (#3)
1 parent d115517 commit 5ac357b

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/__tests__/index.test.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render } from '@testing-library/react';
1+
import { fireEvent, render } from '@testing-library/react';
22
import { axe } from 'jest-axe';
33

44
import { createWizardFlow, useWizardFlow } from 'index';
@@ -43,15 +43,41 @@ describe('#react-wizard-flow', () => {
4343
expect(results).toHaveNoViolations();
4444
});
4545

46-
it('should have functioning transitions', () => {
47-
expect(true).toBe(true);
46+
it('should have functioning transitions', async () => {
47+
const { container, getByText } = render(
48+
<TestWizardFlow.Provider initialStep={TestSteps.step1} steps={STEPS} />,
49+
);
50+
expect(getByText('Step 1')).toBeVisible();
51+
fireEvent.click(getByText("To Step 2"));
52+
expect(getByText('Step 2')).toBeVisible();
53+
const results = await axe(container);
54+
expect(results).toHaveNoViolations();
4855
});
4956

50-
it('should have a functioning close callback', () => {
51-
expect(true).toBe(true);
57+
it('should have a functioning close callback', async () => {
58+
const handleClose = jest.fn();
59+
const { container, getByText } = render(
60+
<TestWizardFlow.Provider initialStep={TestSteps.step1} steps={STEPS} onClose={handleClose} />,
61+
);
62+
expect(getByText('Step 1')).toBeVisible();
63+
expect(handleClose.mock.calls).toHaveLength(0);
64+
fireEvent.click(getByText("Close"));
65+
expect(getByText('Step 1')).toBeVisible();
66+
expect(handleClose.mock.calls).toHaveLength(1);
67+
const results = await axe(container);
68+
expect(results).toHaveNoViolations();
5269
});
5370

5471
it('should not blow up without a close callback', () => {
55-
expect(true).toBe(true);
72+
expect(async () => {
73+
const { container, getByText } = render(
74+
<TestWizardFlow.Provider initialStep={TestSteps.step1} steps={STEPS} />,
75+
);
76+
expect(getByText('Step 1')).toBeVisible();
77+
fireEvent.click(getByText("Close"));
78+
expect(getByText('Step 1')).toBeVisible();
79+
const results = await axe(container);
80+
expect(results).toHaveNoViolations();
81+
}).not.toThrow()
5682
});
5783
});

0 commit comments

Comments
 (0)