File tree Expand file tree Collapse file tree 3 files changed +38
-14
lines changed Expand file tree Collapse file tree 3 files changed +38
-14
lines changed Original file line number Diff line number Diff line change 131
131
"rules": {
132
132
"no-use-before-define": "off",
133
133
"import/no-extraneous-dependencies": "off",
134
- "no-unused-vars": "off"
134
+ "no-unused-vars": "off",
135
+ "react/require-default-props": "off"
135
136
}
136
137
},
137
138
{
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { render , screen } from '../test-utils' ;
3
+ import IconButton from './IconButton' ;
4
+
5
+ const MockIcon = ( props : React . SVGProps < SVGSVGElement > ) => (
6
+ < svg data-testid = "mock-icon" { ...props } />
7
+ ) ;
8
+
9
+ describe ( 'IconButton' , ( ) => {
10
+ test ( 'renders with an icon' , ( ) => {
11
+ render ( < IconButton icon = { MockIcon } aria-label = "test button" /> ) ;
12
+ expect ( screen . getByTestId ( 'mock-icon' ) ) . toBeInTheDocument ( ) ;
13
+ expect (
14
+ screen . getByRole ( 'button' , { name : 'test button' } )
15
+ ) . toBeInTheDocument ( ) ;
16
+ } ) ;
17
+
18
+ test ( 'renders without an icon' , ( ) => {
19
+ render ( < IconButton /> ) ;
20
+ expect ( screen . queryByTestId ( 'mock-icon' ) ) . not . toBeInTheDocument ( ) ;
21
+ } ) ;
22
+
23
+ test ( 'passes other props to the button' , ( ) => {
24
+ render ( < IconButton icon = { MockIcon } id = "my-button" /> ) ;
25
+ expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'id' , 'my-button' ) ;
26
+ } ) ;
27
+ } ) ;
Original file line number Diff line number Diff line change @@ -22,18 +22,14 @@ type IconButtonProps = Omit<
22
22
icon ?: ComponentType < IconProps > | null
23
23
} ;
24
24
25
- const IconButton = ( { icon = null , ...otherProps } : IconButtonProps ) => {
26
- const Icon = icon ;
27
-
28
- return (
29
- < ButtonWrapper
30
- iconBefore = { icon && < Icon /> }
31
- iconOnly
32
- display = { Button . displays . inline }
33
- focusable = "false"
34
- { ...otherProps }
35
- />
36
- ) ;
37
- } ;
25
+ const IconButton = ( { icon : Icon , ...otherProps } : IconButtonProps ) => (
26
+ < ButtonWrapper
27
+ iconBefore = { Icon ? < Icon /> : undefined }
28
+ iconOnly
29
+ display = { Button . displays . inline }
30
+ focusable = "false"
31
+ { ...otherProps }
32
+ />
33
+ ) ;
38
34
39
35
export default IconButton ;
You can’t perform that action at this time.
0 commit comments