You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/hooks/useCombobox/__tests__/props.test.js
+174
Original file line number
Diff line number
Diff line change
@@ -165,6 +165,9 @@ describe('props', () => {
165
165
})
166
166
167
167
test('props update of selectedItem will not update inputValue state if selectedItemChanged returns false',()=>{
168
+
constconsoleWarnSpy=jest
169
+
.spyOn(console,'warn')
170
+
.mockImplementation(()=>{})
168
171
constinitialSelectedItem={id: 1,value: 'hmm'}
169
172
constselectedItem={id: 1,value: 'wow'}
170
173
functionitemToString(item){
@@ -197,6 +200,116 @@ describe('props', () => {
197
200
initialSelectedItem,
198
201
selectedItem,
199
202
)
203
+
expect(consoleWarnSpy).toHaveBeenCalledTimes(1)
204
+
expect(consoleWarnSpy).toHaveBeenCalledWith(
205
+
`The "selectedItemChanged" is deprecated. Please use "itemToKey instead". https://github.com/downshift-js/downshift/blob/master/src/hooks/useCombobox/README.md#selecteditemchanged`,
206
+
)
207
+
consoleWarnSpy.mockRestore()
208
+
})
209
+
})
210
+
211
+
describe('itemToKey',()=>{
212
+
test('props update of selectedItem will update inputValue state with default itemToKey referential equality check',()=>{
213
+
constinitialSelectedItem={id: 3,value: 'init'}
214
+
constselectedItem={id: 1,value: 'wow'}
215
+
constnewSelectedItem={id: 1,value: 'not wow'}
216
+
functionitemToString(item){
217
+
returnitem.value
218
+
}
219
+
conststateReducer=jest
220
+
.fn()
221
+
.mockImplementation((_state,{changes})=>changes)
222
+
223
+
const{rerender}=renderCombobox({
224
+
stateReducer,
225
+
itemToString,
226
+
selectedItem: initialSelectedItem,
227
+
})
228
+
229
+
expect(stateReducer).not.toHaveBeenCalled()// won't get called on first render
`The "selectedItemChanged" is deprecated. Please use "itemToKey instead". https://github.com/downshift-js/downshift/blob/master/src/hooks/useCombobox/README.md#selecteditemchanged`,
0 commit comments