@@ -30,11 +30,7 @@ vi.mock("@/components/ui/field", () => ({
3030 children,
3131 errorText,
3232 invalid,
33- } : {
34- children : ReactElement
35- errorText ?: string
36- invalid : boolean
37- } ) : ReactElement => (
33+ } : { children : ReactElement ; errorText ?: string ; invalid : boolean } ) : ReactElement => (
3834 < div data-invalid = { invalid } >
3935 { children }
4036 { errorText && < span > { errorText } </ span > }
@@ -51,13 +47,7 @@ vi.mock("@/components/ui/input-group", () => ({
5147 * @param {ReactElement } [props.endElement] - The element to render at the end.
5248 * @returns {ReactElement } A mocked div representing the InputGroup.
5349 */
54- InputGroup : ( {
55- children,
56- endElement,
57- } : {
58- children : ReactElement
59- endElement ?: ReactElement
60- } ) : ReactElement => (
50+ InputGroup : ( { children, endElement } : { children : ReactElement ; endElement ?: ReactElement } ) : ReactElement => (
6151 < div >
6252 { children }
6353 { endElement }
@@ -84,30 +74,15 @@ vi.mock("@chakra-ui/react", async (importOriginal) => {
8474 any // Using 'any' here is a pragmatic choice for the mock, as the props are a mix of HTML and Chakra-specific ones.
8575 > ( function MockChakraIconButton ( props , ref ) : ReactElement {
8676 // Correctly destructure and ignore non-standard props for a native button
87- const {
88- aspectRatio,
89- me,
90- size,
91- variant,
92- height,
93- color,
94- children,
95- ...rest // `rest` will now only contain valid HTML button attributes
96- } = props
97-
77+ const { aspectRatio, me, size, variant, height, color, children, ...rest } = props
9878 return (
9979 < button ref = { ref } type = "button" { ...rest } >
10080 { children }
10181 </ button >
10282 )
10383 } )
10484 MockChakraIconButton . displayName = "MockChakraIconButton"
105-
106- return {
107- ...original ,
108- Input : MockChakraInput ,
109- IconButton : MockChakraIconButton ,
110- }
85+ return { ...original , Input : MockChakraInput , IconButton : MockChakraIconButton }
11186} )
11287
11388// endregion
@@ -120,12 +95,8 @@ describe("PasswordInput", () => {
12095 it ( "should render the input and toggle type on click" , async ( ) => {
12196 const user = userEvent . setup ( )
12297 render ( < PasswordInput name = "password" errors = { { } } /> )
123-
12498 const input = screen . getByPlaceholderText < HTMLInputElement > ( "password-input" )
125- const toggleButton = screen . getByRole ( "button" , {
126- name : "Toggle password visibility" ,
127- } )
128-
99+ const toggleButton = screen . getByRole ( "button" , { name : "Toggle password visibility" } )
129100 expect ( input . type ) . toBe ( "password" )
130101 await user . click ( toggleButton )
131102 expect ( input . type ) . toBe ( "text" )
@@ -134,9 +105,7 @@ describe("PasswordInput", () => {
134105 } )
135106
136107 it ( "should display an error message when an error is provided" , ( ) => {
137- const errors : FieldErrors < TestForm > = {
138- password : { type : "required" , message : "This field is required" } ,
139- }
108+ const errors : FieldErrors < TestForm > = { password : { type : "required" , message : "This field is required" } }
140109 render ( < PasswordInput name = "password" errors = { errors } /> )
141110 expect ( screen . getByText ( "This field is required" ) ) . toBeInTheDocument ( )
142111 } )
0 commit comments