@@ -3,6 +3,7 @@ import { fireEvent, render } from '@testing-library/react';
33import KeyCode from '@rc-component/util/lib/KeyCode' ;
44import React from 'react' ;
55import Menu , { MenuItem , MenuItemGroup , SubMenu } from '../src' ;
6+ import { MenuItemType } from '@/interface' ;
67
78describe ( 'MenuItem' , ( ) => {
89 const subMenuIconText = 'SubMenuIcon' ;
@@ -181,15 +182,15 @@ describe('MenuItem', () => {
181182 ) ;
182183 } ) ;
183184
184- it ( 'should pass itemData in onSelect and onClick with items ' , ( ) => {
185+ it ( 'should only pass defined itemData properties in onSelect and onClick' , ( ) => {
185186 const onSelect = jest . fn ( ) ;
186187 const onClick = jest . fn ( ) ;
187188 const { container } = render (
188189 < Menu
189190 onSelect = { onSelect }
190191 onClick = { onClick }
191192 selectable
192- items = { [ { key : '1' , label : 'Menu Item' } ] }
193+ items = { [ { key : '1' , label : 'Menu Item' , foo : '123' } ] as any }
193194 /> ,
194195 ) ;
195196
@@ -203,6 +204,14 @@ describe('MenuItem', () => {
203204 } ) ,
204205 } ) ,
205206 ) ;
207+ expect ( onSelect ) . toHaveBeenCalledWith (
208+ expect . objectContaining ( {
209+ key : '1' ,
210+ itemData : expect . not . objectContaining ( {
211+ foo : '123' ,
212+ } ) ,
213+ } ) ,
214+ ) ;
206215 expect ( onClick ) . toHaveBeenCalledWith (
207216 expect . objectContaining ( {
208217 key : '1' ,
@@ -212,6 +221,14 @@ describe('MenuItem', () => {
212221 } ) ,
213222 } ) ,
214223 ) ;
224+ expect ( onClick ) . toHaveBeenCalledWith (
225+ expect . objectContaining ( {
226+ key : '1' ,
227+ itemData : expect . not . objectContaining ( {
228+ foo : '123' ,
229+ } ) ,
230+ } ) ,
231+ ) ;
215232 } ) ;
216233 } ) ;
217234
0 commit comments