11import * as React from 'react' ;
2+ import { render } from '@testing-library/react' ;
23import { renderHook } from '@testing-library/react-hooks' ;
34import '@testing-library/jest-dom' ;
45import { ButtonContextProvider } from '../../contexts/ButtonContext' ;
56import type { ButtonContextValue } from '../../contexts/ButtonContext' ;
67import { useMenuButton_unstable } from './useMenuButton' ;
8+ import { MenuButton } from './MenuButton' ;
79
810const wrap = ( contextValue : ButtonContextValue = { } ) : React . FC < { children ?: React . ReactNode } > => {
911 const Wrapper : React . FC < { children ?: React . ReactNode } > = ( { children } ) => (
@@ -19,10 +21,9 @@ describe('useMenuButton_unstable', () => {
1921 expect ( result . current . components ) . toEqual ( { root : 'button' , icon : 'span' , menuIcon : 'span' } ) ;
2022 } ) ;
2123
22- it ( 'renders a menuIcon slot with a default chevron icon' , ( ) => {
23- const { result } = renderHook ( ( ) => useMenuButton_unstable ( { } , React . createRef ( ) ) ) ;
24- expect ( result . current . menuIcon ) . toBeDefined ( ) ;
25- expect ( React . isValidElement ( result . current . menuIcon ?. children ) ) . toBe ( true ) ;
24+ it ( 'renders a menuIcon slot with a default icon' , ( ) => {
25+ const result = render ( < MenuButton /> ) ;
26+ expect ( result . container . querySelector ( 'svg' ) ) . toBeInTheDocument ( ) ;
2627 } ) ;
2728
2829 it ( 'preserves a user-provided menuIcon over the default chevron' , ( ) => {
@@ -33,6 +34,16 @@ describe('useMenuButton_unstable', () => {
3334 expect ( result . current . menuIcon ?. children ) . toBe ( customIcon ) ;
3435 } ) ;
3536
37+ it ( 'renders the default chevron when menuIcon is explicitly undefined' , ( ) => {
38+ const result = render ( < MenuButton menuIcon = { undefined } /> ) ;
39+ expect ( result . container . querySelector ( 'svg' ) ) . toBeInTheDocument ( ) ;
40+ } ) ;
41+
42+ it ( 'hides the menuIcon slot when menuIcon is null' , ( ) => {
43+ const { result } = renderHook ( ( ) => useMenuButton_unstable ( { menuIcon : null } , React . createRef ( ) ) ) ;
44+ expect ( result . current . menuIcon ) . toBeUndefined ( ) ;
45+ } ) ;
46+
3647 it ( 'defaults aria-expanded to false when not provided' , ( ) => {
3748 const { result } = renderHook ( ( ) => useMenuButton_unstable ( { } , React . createRef ( ) ) ) ;
3849 expect ( result . current . root [ 'aria-expanded' ] ) . toBe ( false ) ;
0 commit comments