Skip to content

Commit c7c9ebb

Browse files
committed
refactor(test): user-event^14 마이그레이션
https://testing-library.com/docs/user-event/intro
1 parent 626f271 commit c7c9ebb

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/components/Forms/Inputs/Select/Select.test.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ describe('Select Test >', () => {
8080
expect(defaultSelectTrigger).toHaveStyle('cursor: pointer;')
8181
})
8282

83-
it('Dropdown >', () => {
83+
it('Dropdown >', async () => {
84+
const user = userEvent.setup()
8485
const { getByTestId } = renderSelect()
8586

8687
const defaultSelectTrigger = getByTestId(SELECT_TRIGGER_TEST_ID)
87-
userEvent.click(defaultSelectTrigger)
88+
await user.click(defaultSelectTrigger)
8889

8990
const defaultSelectDropdown = getByTestId(SELECT_DROPDOWN_TEST_ID)
9091

@@ -96,7 +97,8 @@ describe('Select Test >', () => {
9697
})
9798

9899
describe('SelectSize >', () => {
99-
it('Size only effects to trigger style >', () => {
100+
it('Size only effects to trigger style >', async () => {
101+
const user = userEvent.setup()
100102
const XL_CONTAINER_TEST_ID = `${SELECT_CONTAINER_TEST_ID}_XL`
101103
const XL_TRIGGER_TEST_ID = `${SELECT_TRIGGER_TEST_ID}_XL`
102104
const XL_DROPDOWN_TEST_ID = `${SELECT_DROPDOWN_TEST_ID}_XL`
@@ -121,21 +123,21 @@ describe('Select Test >', () => {
121123
const xlSelectContainer = getByTestIdForXL(XL_CONTAINER_TEST_ID)
122124
const xlSelectTrigger = getByTestIdForXL(XL_TRIGGER_TEST_ID)
123125
// Open Dropdown
124-
userEvent.click(xlSelectTrigger)
126+
await user.click(xlSelectTrigger)
125127
const xlSelectDropdown = getByTestIdForXL(XL_DROPDOWN_TEST_ID)
126128
// Close Dropdown
127-
userEvent.click(xlSelectTrigger)
129+
await user.click(xlSelectTrigger)
128130
const xlContainerStyle = window.getComputedStyle(xlSelectContainer)
129131
const xlDropdownStyle = window.getComputedStyle(xlSelectDropdown)
130132

131133
// Select Size.L
132134
const lSelectContainer = getByTestIdForL(L_CONTAINER_TEST_ID)
133135
const lSelectTrigger = getByTestIdForL(L_TRIGGER_TEST_ID)
134136
// Open Dropdown
135-
userEvent.click(lSelectTrigger)
137+
await user.click(lSelectTrigger)
136138
const lSelectDropdown = getByTestIdForL(L_DROPDOWN_TEST_ID)
137139
// Close Dropdown
138-
userEvent.click(lSelectTrigger)
140+
await user.click(lSelectTrigger)
139141
const lContainerStyle = window.getComputedStyle(lSelectContainer)
140142
const lDropdownStyle = window.getComputedStyle(lSelectDropdown)
141143

@@ -216,11 +218,12 @@ describe('Select Test >', () => {
216218
expect(trigger).toHaveStyle('cursor: not-allowed')
217219
})
218220

219-
it('should not show dropdown when clicked', () => {
221+
it('should not show dropdown when clicked', async () => {
222+
const user = userEvent.setup()
220223
const { getByTestId } = renderSelect({ disabled: true })
221224
const trigger = getByTestId(SELECT_TRIGGER_TEST_ID)
222225

223-
userEvent.click(trigger)
226+
await user.click(trigger)
224227

225228
expect(() => getByTestId(SELECT_DROPDOWN_TEST_ID)).toThrow() // element should not exist
226229
})
@@ -257,11 +260,12 @@ describe('Select Test >', () => {
257260
expect(trigger).toHaveStyle('cursor: initial')
258261
})
259262

260-
it('should not show dropdown when clicked', () => {
263+
it('should not show dropdown when clicked', async () => {
264+
const user = userEvent.setup()
261265
const { getByTestId } = renderSelect({ readOnly: true })
262266
const trigger = getByTestId(SELECT_TRIGGER_TEST_ID)
263267

264-
userEvent.click(trigger)
268+
await user.click(trigger)
265269

266270
expect(() => getByTestId(SELECT_DROPDOWN_TEST_ID)).toThrow() // element should not exist
267271
})
@@ -289,13 +293,14 @@ describe('Select Test >', () => {
289293
expect(dropdown).toBeVisible()
290294
})
291295

292-
it('should disappear dropdown when the other elements clicked >', () => {
296+
it('should disappear dropdown when the other elements clicked >', async () => {
293297
const { body } = document
298+
const user = userEvent.setup()
294299

295300
const { getByTestId } = renderSelect({ defaultFocus: true })
296301
const dropdown = getByTestId(SELECT_DROPDOWN_TEST_ID)
297302

298-
userEvent.click(body)
303+
await user.click(body)
299304

300305
expect(dropdown).not.toBeVisible()
301306
})

0 commit comments

Comments
 (0)