Skip to content

Commit 22443c2

Browse files
committed
fix: use findBy queries instead of waitFor with user interactions in DeductionsForm tests
1 parent 4cbe6e8 commit 22443c2

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

src/components/Employee/Deductions/DeductionsForm/DeductionsForm.test.tsx

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,54 +110,51 @@ describe('DeductionsForm', () => {
110110
it('can switch between garnishment or custom deduction', async () => {
111111
renderDeductionsForm()
112112

113-
await waitFor(async () => {
114-
const garnishmentRadio = screen.getByLabelText('Garnishment (a court-ordered deduction)')
115-
116-
await user.click(garnishmentRadio)
113+
const garnishmentRadio = await screen.findByLabelText(
114+
'Garnishment (a court-ordered deduction)',
115+
)
116+
await user.click(garnishmentRadio)
117117

118-
// 1 p tag, and 1 input label
118+
await waitFor(() => {
119119
expect(screen.getAllByText('Garnishment type').length).toEqual(2)
120+
})
120121

121-
const customRadio = screen.getByLabelText('Custom deduction (post-tax)')
122-
123-
await user.click(customRadio)
122+
const customRadio = screen.getByLabelText('Custom deduction (post-tax)')
123+
await user.click(customRadio)
124124

125-
expect(customRadio).toBeChecked()
126-
expect(screen.getByText('Description')).toBeInTheDocument()
127-
})
125+
expect(customRadio).toBeChecked()
126+
expect(screen.getByText('Description')).toBeInTheDocument()
128127
})
129128

130129
it('can switch between garnishment types', async () => {
131130
renderDeductionsForm()
132131

133-
await waitFor(async () => {
134-
const garnishmentRadio = screen.getByLabelText('Garnishment (a court-ordered deduction)')
135-
136-
await user.click(garnishmentRadio)
132+
const garnishmentRadio = await screen.findByLabelText(
133+
'Garnishment (a court-ordered deduction)',
134+
)
135+
await user.click(garnishmentRadio)
137136

138-
// 1 p tag, and 1 input label
137+
await waitFor(() => {
139138
expect(screen.getAllByText('Garnishment type').length).toEqual(2)
140-
expect(screen.getByLabelText('Child Support')).toBeInTheDocument()
139+
})
141140

142-
await user.click(screen.getByRole('button', { name: 'Child Support Garnishment type' }))
143-
await user.click(screen.getByRole('option', { name: 'Federal Tax Lien' }))
141+
expect(screen.getByLabelText('Child Support')).toBeInTheDocument()
144142

143+
await user.click(screen.getByRole('button', { name: 'Child Support Garnishment type' }))
144+
await user.click(screen.getByRole('option', { name: 'Federal Tax Lien' }))
145+
146+
await waitFor(() => {
145147
expect(screen.getByLabelText('Federal Tax Lien')).toBeInTheDocument()
146148
})
147149
})
148150

149151
it('can go back', async () => {
150152
renderDeductionsForm()
151153

152-
await waitFor(async () => {
153-
const backButton = screen.getByRole('button', { name: 'Back to deductions' })
154+
const backButton = await screen.findByRole('button', { name: 'Back to deductions' })
155+
await user.click(backButton)
154156

155-
expect(backButton).toBeInTheDocument()
156-
157-
await user.click(backButton)
158-
159-
expect(mockOnEvent).toHaveBeenCalledWith(componentEvents.EMPLOYEE_DEDUCTION_CANCEL_EMPTY)
160-
})
157+
expect(mockOnEvent).toHaveBeenCalledWith(componentEvents.EMPLOYEE_DEDUCTION_CANCEL_EMPTY)
161158
})
162159
})
163160
})

0 commit comments

Comments
 (0)