@instructure/ui-checkbox 9.2.1-snapshot-1 → 9.2.1-snapshot-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,7 @@
24
24
 
25
25
  import React from 'react'
26
26
  import { fireEvent, render, screen, waitFor } from '@testing-library/react'
27
+ import { vi } from 'vitest'
27
28
  import userEvent from '@testing-library/user-event'
28
29
  import '@testing-library/jest-dom'
29
30
 
@@ -51,6 +52,24 @@ const renderCheckbox = (props?: Partial<CheckboxProps>) => {
51
52
  }
52
53
 
53
54
  describe('<Checkbox />', () => {
55
+ let consoleWarningMock: ReturnType<typeof vi.spyOn>
56
+ let consoleErrorMock: ReturnType<typeof vi.spyOn>
57
+
58
+ beforeEach(() => {
59
+ // Mocking console to prevent test output pollution
60
+ consoleWarningMock = vi
61
+ .spyOn(console, 'warn')
62
+ .mockImplementation(() => {}) as any
63
+ consoleErrorMock = vi
64
+ .spyOn(console, 'error')
65
+ .mockImplementation(() => {}) as any
66
+ })
67
+
68
+ afterEach(() => {
69
+ consoleWarningMock.mockRestore()
70
+ consoleErrorMock.mockRestore()
71
+ })
72
+
54
73
  it('renders an input with type "checkbox"', () => {
55
74
  renderCheckbox()
56
75
  const inputElem = screen.getByRole('checkbox')
@@ -88,8 +107,8 @@ describe('<Checkbox />', () => {
88
107
 
89
108
  describe('events', () => {
90
109
  it('when clicked, fires onClick and onChange events', async () => {
91
- const onClick = jest.fn()
92
- const onChange = jest.fn()
110
+ const onClick = vi.fn()
111
+ const onChange = vi.fn()
93
112
  renderCheckbox({ onClick, onChange })
94
113
  const checkboxElement = screen.getByRole('checkbox')
95
114
 
@@ -102,8 +121,8 @@ describe('<Checkbox />', () => {
102
121
  })
103
122
 
104
123
  it('when clicked, does not call onClick or onChange when disabled', async () => {
105
- const onClick = jest.fn()
106
- const onChange = jest.fn()
124
+ const onClick = vi.fn()
125
+ const onChange = vi.fn()
107
126
  renderCheckbox({ onClick, onChange, disabled: true })
108
127
  const checkboxElement = screen.getByRole('checkbox')
109
128
 
@@ -117,8 +136,8 @@ describe('<Checkbox />', () => {
117
136
  })
118
137
 
119
138
  it('when clicked, does not call onClick or onChange when readOnly', async () => {
120
- const onClick = jest.fn()
121
- const onChange = jest.fn()
139
+ const onClick = vi.fn()
140
+ const onChange = vi.fn()
122
141
  renderCheckbox({ onClick, onChange, readOnly: true })
123
142
  const checkboxElement = screen.getByRole('checkbox')
124
143
 
@@ -131,7 +150,7 @@ describe('<Checkbox />', () => {
131
150
  })
132
151
 
133
152
  it('calls onChange when enter key is pressed', async () => {
134
- const onChange = jest.fn()
153
+ const onChange = vi.fn()
135
154
  renderCheckbox({ onChange })
136
155
  const checkboxElement = screen.getByRole('checkbox')
137
156
 
@@ -143,7 +162,7 @@ describe('<Checkbox />', () => {
143
162
  })
144
163
 
145
164
  it('responds to onBlur event', async () => {
146
- const onBlur = jest.fn()
165
+ const onBlur = vi.fn()
147
166
  renderCheckbox({ onBlur })
148
167
 
149
168
  userEvent.tab()
@@ -155,7 +174,7 @@ describe('<Checkbox />', () => {
155
174
  })
156
175
 
157
176
  it('responds to onFocus event', async () => {
158
- const onFocus = jest.fn()
177
+ const onFocus = vi.fn()
159
178
  renderCheckbox({ onFocus })
160
179
 
161
180
  userEvent.tab()
@@ -178,7 +197,7 @@ describe('<Checkbox />', () => {
178
197
  })
179
198
 
180
199
  it('calls onMouseOver', async () => {
181
- const onMouseOver = jest.fn()
200
+ const onMouseOver = vi.fn()
182
201
  renderCheckbox({ onMouseOver })
183
202
  const checkboxElement = screen.getByRole('checkbox')
184
203
 
@@ -190,7 +209,7 @@ describe('<Checkbox />', () => {
190
209
  })
191
210
 
192
211
  it('calls onMouseOut', async () => {
193
- const onMouseOut = jest.fn()
212
+ const onMouseOut = vi.fn()
194
213
  renderCheckbox({ onMouseOut })
195
214
  const checkboxElement = screen.getByRole('checkbox')
196
215
 
@@ -24,6 +24,7 @@
24
24
 
25
25
  import React from 'react'
26
26
  import { fireEvent, render, screen, waitFor } from '@testing-library/react'
27
+ import { vi } from 'vitest'
27
28
  import userEvent from '@testing-library/user-event'
28
29
  import '@testing-library/jest-dom'
29
30
 
@@ -56,6 +57,24 @@ const renderCheckboxGroup = (props?: Partial<CheckboxGroupProps>) => {
56
57
  }
57
58
 
58
59
  describe('<CheckboxGroup />', () => {
60
+ let consoleWarningMock: ReturnType<typeof vi.spyOn>
61
+ let consoleErrorMock: ReturnType<typeof vi.spyOn>
62
+
63
+ beforeEach(() => {
64
+ // Mocking console to prevent test output pollution
65
+ consoleWarningMock = vi
66
+ .spyOn(console, 'warn')
67
+ .mockImplementation(() => {}) as any
68
+ consoleErrorMock = vi
69
+ .spyOn(console, 'error')
70
+ .mockImplementation(() => {}) as any
71
+ })
72
+
73
+ afterEach(() => {
74
+ consoleWarningMock.mockRestore()
75
+ consoleErrorMock.mockRestore()
76
+ })
77
+
59
78
  it('adds the name props to all Checkbox types', () => {
60
79
  renderCheckboxGroup({ name: TEST_NAME })
61
80
  const checkboxes = screen.getAllByRole('checkbox')
@@ -86,7 +105,7 @@ describe('<CheckboxGroup />', () => {
86
105
  })
87
106
 
88
107
  it('does not call the onChange prop when disabled', async () => {
89
- const onChange = jest.fn()
108
+ const onChange = vi.fn()
90
109
  renderCheckboxGroup({ onChange, disabled: true })
91
110
  const checkboxElement = screen.getAllByRole('checkbox')[0]
92
111
 
@@ -99,7 +118,7 @@ describe('<CheckboxGroup />', () => {
99
118
  })
100
119
 
101
120
  it('does not call the onChange prop when readOnly', async () => {
102
- const onChange = jest.fn()
121
+ const onChange = vi.fn()
103
122
  renderCheckboxGroup({ onChange, readOnly: true })
104
123
  const checkboxElement = screen.getAllByRole('checkbox')[0]
105
124
 
@@ -112,7 +131,7 @@ describe('<CheckboxGroup />', () => {
112
131
  })
113
132
 
114
133
  it('should not update the value when the value prop is set', async () => {
115
- const onChange = jest.fn()
134
+ const onChange = vi.fn()
116
135
  renderCheckboxGroup({ onChange, value: ['tester'] })
117
136
  const checkboxes = screen.getAllByRole('checkbox')
118
137
 
@@ -129,7 +148,7 @@ describe('<CheckboxGroup />', () => {
129
148
  })
130
149
 
131
150
  it('should add the checkbox value to the value list when it is checked', async () => {
132
- const onChange = jest.fn()
151
+ const onChange = vi.fn()
133
152
  renderCheckboxGroup({ onChange })
134
153
  const checkboxes = screen.getAllByRole('checkbox')
135
154
 
@@ -156,7 +175,7 @@ describe('<CheckboxGroup />', () => {
156
175
  })
157
176
 
158
177
  it('should remove the checkbox value from the value list when it is unchecked', async () => {
159
- const onChange = jest.fn()
178
+ const onChange = vi.fn()
160
179
  const defaultValue = [TEST_VALUE_1, TEST_VALUE_2]
161
180
  renderCheckboxGroup({ onChange, defaultValue })
162
181
  const checkboxes = screen.getAllByRole('checkbox')
@@ -174,7 +193,7 @@ describe('<CheckboxGroup />', () => {
174
193
  })
175
194
 
176
195
  it('passes the array of selected values to onChange handler', async () => {
177
- const onChange = jest.fn()
196
+ const onChange = vi.fn()
178
197
  const defaultValue = [TEST_VALUE_2]
179
198
  renderCheckboxGroup({ onChange, defaultValue })
180
199
  const checkboxes = screen.getAllByRole('checkbox')