@@ -5,9 +5,12 @@ import { render } from '@testing-library/react';
5
5
import FormField , { FormFieldProps } from '../../../lib/components/form-field' ;
6
6
import Input from '../../../lib/components/input' ;
7
7
import createWrapper from '../../../lib/components/test-utils/dom' ;
8
+ import styles from '../../../lib/components/form-field/styles.css.js' ;
8
9
9
10
const testInput = < Input value = "follow me on tiktok" onChange = { ( ) => { } } /> ;
10
11
12
+ const errorSelector = `:scope > .${ styles . hints } .${ styles . error } ` ;
13
+
11
14
function renderFormField ( props : FormFieldProps = { } ) {
12
15
const renderResult = render ( < FormField { ...props } /> ) ;
13
16
return createWrapper ( renderResult . container ) . findFormField ( ) ! ;
@@ -33,7 +36,7 @@ describe('controlId', () => {
33
36
34
37
test ( 'renders id for errorText based on controlId' , ( ) => {
35
38
const wrapper = renderFormField ( { controlId : formFieldControlId , errorText : 'Test error' } ) ;
36
- expect ( wrapper . findError ( ) ?. getElement ( ) . id ) . toBe ( `${ formFieldControlId } -error` ) ;
39
+ expect ( wrapper . find ( errorSelector ) ?. getElement ( ) . id ) . toBe ( `${ formFieldControlId } -error` ) ;
37
40
} ) ;
38
41
39
42
test ( 'renders id for constraintText based on controlId' , ( ) => {
@@ -52,7 +55,7 @@ describe('controlId', () => {
52
55
53
56
expect ( wrapper . findLabel ( ) ?. getElement ( ) ) . toHaveAttribute ( 'for' , formFieldControlId ) ;
54
57
expect ( wrapper . findDescription ( ) ?. getElement ( ) . id ) . toBe ( `${ formFieldControlId } -description` ) ;
55
- expect ( wrapper . findError ( ) ?. getElement ( ) . id ) . toBe ( `${ formFieldControlId } -error` ) ;
58
+ expect ( wrapper . find ( errorSelector ) ?. getElement ( ) . id ) . toBe ( `${ formFieldControlId } -error` ) ;
56
59
expect ( wrapper . findConstraint ( ) ?. getElement ( ) . id ) . toBe ( `${ formFieldControlId } -constraint` ) ;
57
60
} ) ;
58
61
@@ -109,7 +112,7 @@ describe('controlId', () => {
109
112
110
113
test ( 'generates own id and uses it for errorText' , ( ) => {
111
114
const wrapper = renderFormField ( { errorText : 'Test error' } ) ;
112
- expect ( wrapper . findError ( ) ?. getElement ( ) ) . toHaveAttribute ( 'id' ) ;
115
+ expect ( wrapper . find ( errorSelector ) ?. getElement ( ) ) . toHaveAttribute ( 'id' ) ;
113
116
} ) ;
114
117
115
118
test ( 'generates own id and uses it for constraintText' , ( ) => {
@@ -129,7 +132,7 @@ describe('controlId', () => {
129
132
130
133
expect ( labelId ) . not . toBeUndefined ( ) ;
131
134
expect ( wrapper . findDescription ( ) ?. getElement ( ) . id ) . toBe ( labelId ?. replace ( 'label' , 'description' ) ) ;
132
- expect ( wrapper . findError ( ) ?. getElement ( ) . id ) . toBe ( labelId ?. replace ( 'label' , 'error' ) ) ;
135
+ expect ( wrapper . find ( errorSelector ) ?. getElement ( ) . id ) . toBe ( labelId ?. replace ( 'label' , 'error' ) ) ;
133
136
expect ( wrapper . findConstraint ( ) ?. getElement ( ) . id ) . toBe ( labelId ?. replace ( 'label' , 'constraint' ) ) ;
134
137
} ) ;
135
138
0 commit comments