Skip to content

Commit 252fa37

Browse files
chore(devdeps): update dependency eslint-plugin-testing-library to v7.5.3 (#5268)
* chore(devdeps): update dependency eslint-plugin-testing-library to v7.5.3 * fix: unit tests * fix: lint issues * fix: testing library --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Matthias <[email protected]>
1 parent 979d9d9 commit 252fa37

File tree

19 files changed

+1547
-1310
lines changed

19 files changed

+1547
-1310
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"esbuild-plugin-browserslist": "1.0.1",
159159
"eslint": "9.29.0",
160160
"eslint-plugin-oxlint": "0.18.1",
161-
"eslint-plugin-testing-library": "7.4.0",
161+
"eslint-plugin-testing-library": "7.5.3",
162162
"expect": "29.7.0",
163163
"file-loader": "6.2.0",
164164
"globals": "16.2.0",

packages/form/src/components/CheckboxField/__tests__/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('CheckboxField', () => {
5252
expect(asFragment()).toMatchSnapshot()
5353
})
5454

55-
test('should trigger events correctly', () => {
55+
test('should trigger events correctly', async () => {
5656
const onFocus = vi.fn(() => {})
5757
const onChange = vi.fn(() => {})
5858
const onBlur = vi.fn(() => {})
@@ -71,7 +71,7 @@ describe('CheckboxField', () => {
7171
const input = screen.getByRole('checkbox', { hidden: true })
7272
act(() => input.focus())
7373
expect(onFocus).toBeCalledTimes(1)
74-
act(() => input.click())
74+
await userEvent.click(input)
7575
expect(onChange).toBeCalledTimes(1)
7676
act(() => input.blur())
7777
expect(onBlur).toBeCalledTimes(1)

packages/form/src/components/CheckboxGroupField/__tests__/index.test.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { act, screen } from '@testing-library/react'
1+
import { screen } from '@testing-library/react'
2+
import { userEvent } from '@testing-library/user-event'
23
import { renderWithForm } from '@utils/test'
34
import { describe, expect, test, vi } from 'vitest'
45
import { CheckboxGroupField } from '..'
56

67
describe('CheckboxField', () => {
7-
test('should render correctly checked', () => {
8+
test('should render correctly checked', async () => {
89
const { asFragment } = renderWithForm(
910
<CheckboxGroupField onChange={() => {}} name="Checkbox" legend="Label">
1011
<CheckboxGroupField.Checkbox name="value-1" value="value-1">
@@ -26,14 +27,14 @@ describe('CheckboxField', () => {
2627
hidden: true,
2728
},
2829
)
29-
act(() => secondInput.click())
30+
await userEvent.click(secondInput)
3031

3132
expect(firstInput).not.toBeChecked()
3233
expect(secondInput).toBeChecked()
3334
expect(asFragment()).toMatchSnapshot()
3435
})
3536

36-
test('should trigger events correctly with required prop', () => {
37+
test('should trigger events correctly with required prop', async () => {
3738
const onChange = vi.fn(() => {})
3839

3940
const { asFragment } = renderWithForm(
@@ -57,11 +58,11 @@ describe('CheckboxField', () => {
5758
},
5859
)
5960
const input = screen.getAllByRole('checkbox', { hidden: true })[0]
60-
act(() => input.click())
61+
await userEvent.click(input)
6162
expect(onChange).toBeCalledTimes(1)
6263
expect(input).toBeChecked()
6364

64-
act(() => input.click())
65+
await userEvent.click(input)
6566
expect(onChange).toBeCalledTimes(2)
6667
expect(input).not.toBeChecked()
6768

packages/form/src/components/KeyValueField/__tests__/index.test.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { act, screen } from '@testing-library/react'
1+
import { screen } from '@testing-library/react'
2+
import { userEvent } from '@testing-library/user-event'
23
import { renderWithForm } from '@utils/test'
34
import { describe, expect, it } from 'vitest'
45
import { KeyValueField } from '..'
56

67
describe('KeyValueField', () => {
7-
it('should render with default props', () => {
8+
it('should render with default props', async () => {
89
const { asFragment } = renderWithForm(
910
<KeyValueField
1011
name="test"
@@ -23,14 +24,10 @@ describe('KeyValueField', () => {
2324
/>,
2425
)
2526
const addButton = screen.getByTestId('add-button')
26-
act(() => {
27-
addButton.click()
28-
})
27+
await userEvent.click(addButton)
2928

3029
const removeButton = screen.getByTestId('remove-button-0')
31-
act(() => {
32-
removeButton.click()
33-
})
30+
await userEvent.click(removeButton)
3431
expect(asFragment()).toMatchSnapshot()
3532
})
3633

packages/form/src/components/NumberInputField/__tests__/index.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('NumberInputField', () => {
3434
expect(asFragment()).toMatchSnapshot()
3535
})
3636

37-
test('should trigger events correctly', () => {
37+
test('should trigger events correctly', async () => {
3838
const onFocus = vi.fn(() => {})
3939
const onChange = vi.fn(() => {})
4040
const onBlur = vi.fn(() => {})
@@ -57,9 +57,7 @@ describe('NumberInputField', () => {
5757
input.focus()
5858
})
5959
expect(onFocus).toBeCalledTimes(1)
60-
act(() => {
61-
input.click()
62-
})
60+
await userEvent.click(input)
6361
expect(onChange).toBeCalledTimes(0)
6462
act(() => {
6563
input.blur()

packages/form/src/components/RadioField/__tests__/index.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { act, screen } from '@testing-library/react'
2+
import { userEvent } from '@testing-library/user-event'
23
import { renderWithForm } from '@utils/test'
34
import { describe, expect, test, vi } from 'vitest'
45
import { RadioField } from '..'
@@ -42,7 +43,7 @@ describe('RadioField', () => {
4243
expect(asFragment()).toMatchSnapshot()
4344
})
4445

45-
test('should trigger events correctly', () => {
46+
test('should trigger events correctly', async () => {
4647
const onFocus = vi.fn(() => {})
4748
const onChange = vi.fn(() => {})
4849
const onBlur = vi.fn(() => {})
@@ -60,7 +61,7 @@ describe('RadioField', () => {
6061
const input = screen.getByRole('radio', { hidden: true })
6162
act(() => input.focus())
6263
expect(onFocus).toBeCalledTimes(1)
63-
act(() => input.click())
64+
await userEvent.click(input)
6465
expect(onChange).toBeCalledTimes(1)
6566
act(() => input.blur())
6667
expect(onBlur).toBeCalledTimes(1)

packages/form/src/components/RadioGroupField/__tests__/index.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { act, screen } from '@testing-library/react'
1+
import { screen } from '@testing-library/react'
2+
import { userEvent } from '@testing-library/user-event'
23
import { renderWithForm } from '@utils/test'
34
import { describe, expect, test, vi } from 'vitest'
45
import { RadioGroupField } from '..'
56

67
describe('RadioField', () => {
7-
test('should render correctly checked', () => {
8+
test('should render correctly checked', async () => {
89
const { asFragment } = renderWithForm(
910
<RadioGroupField
1011
value="value-1"
@@ -19,15 +20,15 @@ describe('RadioField', () => {
1920
const [firstInput, secondInput] = screen.getAllByRole('radio', {
2021
hidden: true,
2122
})
22-
act(() => secondInput.click())
23+
await userEvent.click(secondInput)
2324

2425
expect(firstInput).not.toBeChecked()
2526
expect(secondInput).toBeChecked()
2627

2728
expect(asFragment()).toMatchSnapshot()
2829
})
2930

30-
test('should trigger events correctly', () => {
31+
test('should trigger events correctly', async () => {
3132
const onChange = vi.fn(() => {})
3233

3334
const { asFragment } = renderWithForm(
@@ -42,7 +43,7 @@ describe('RadioField', () => {
4243
</RadioGroupField>,
4344
)
4445
const input = screen.getAllByRole('radio', { hidden: true })[0]
45-
act(() => input.click())
46+
await userEvent.click(input)
4647
expect(onChange).toBeCalledTimes(1)
4748
expect(asFragment()).toMatchSnapshot()
4849
})

packages/form/src/components/SelectInputField/__tests__/index.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { act, fireEvent, screen } from '@testing-library/react'
2+
import { userEvent } from '@testing-library/user-event'
23
import { renderWithForm } from '@utils/test'
34
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
45
import { SelectInputField } from '..'
@@ -50,7 +51,7 @@ describe('SelectInputField', () => {
5051
expect(asFragment()).toMatchSnapshot()
5152
})
5253

53-
test('should display right value on grouped options', () => {
54+
test('should display right value on grouped options', async () => {
5455
const selectedOption = { label: 'Group Label', value: 'Group Value' }
5556
const options = [
5657
{
@@ -73,7 +74,7 @@ describe('SelectInputField', () => {
7374
// eslint-disable-next-line testing-library/no-node-access
7475
).firstChild as HTMLElement
7576

76-
act(() => option.click())
77+
await userEvent.click(option)
7778

7879
// react-select works with a hidden input to handle value.
7980
// eslint-disable-next-line testing-library/no-node-access, testing-library/no-container
@@ -86,7 +87,7 @@ describe('SelectInputField', () => {
8687
expect(asFragment()).toMatchSnapshot()
8788
})
8889

89-
test('should trigger events', () => {
90+
test('should trigger events', async () => {
9091
const onChange = vi.fn()
9192

9293
const { asFragment } = renderWithForm(
@@ -105,7 +106,7 @@ describe('SelectInputField', () => {
105106
// eslint-disable-next-line testing-library/no-node-access
106107
screen.getByTestId('option-test-value').firstChild as HTMLElement
107108

108-
act(() => option.click())
109+
await userEvent.click(option)
109110
expect(onChange).toBeCalledTimes(1)
110111
act(() => select.blur())
111112
expect(asFragment()).toMatchSnapshot()

packages/form/src/components/SelectInputFieldV2/__tests__/index.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ describe('SelectInputField', () => {
3939
<SelectInputFieldV2 name="test" options={planets} searchable={false} />,
4040
)
4141
const select = screen.getByTestId('select-input-test')
42-
act(() => select.click())
42+
await userEvent.click(select)
4343
fireEvent.keyDown(select, { key: 'ArrowDown', keyCode: 40 })
4444
const mercury = screen.getByTestId(`option-stack-mercury`)
4545

46-
act(() => mercury.click())
47-
act(() => select.click())
46+
await userEvent.click(mercury)
47+
await userEvent.click(select)
4848
await waitFor(() => {
4949
expect(screen.getByTestId(`option-stack-mercury`)).toBeVisible()
5050
})

packages/form/src/components/SelectableCardField/__tests__/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('SelectableCardField', () => {
3737
expect(asFragment()).toMatchSnapshot()
3838
})
3939

40-
test('should trigger events correctly', () => {
40+
test('should trigger events correctly', async () => {
4141
const onFocus = vi.fn(() => {})
4242
const onChange = vi.fn(() => {})
4343
const onBlur = vi.fn(() => {})
@@ -57,7 +57,7 @@ describe('SelectableCardField', () => {
5757
const input = screen.getByRole('radio', { hidden: true })
5858
act(() => input.focus())
5959
expect(onFocus).toBeCalledTimes(1)
60-
act(() => input.click())
60+
await userEvent.click(input)
6161
expect(onChange).toBeCalledTimes(1)
6262
act(() => input.blur())
6363
expect(onBlur).toBeCalledTimes(1)

0 commit comments

Comments
 (0)