Skip to content

Commit d16170e

Browse files
committed
Fix test
1 parent ce4b5ed commit d16170e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

packages/react/src/field/control/useFieldControlValidation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ export function useFieldControlValidation() {
150150

151151
const nextState = getState(element);
152152

153+
let defaultValidationMessage;
154+
153155
if (element.validationMessage) {
156+
defaultValidationMessage = element.validationMessage;
154157
validationErrors = [element.validationMessage];
155158
} else {
156159
const resultOrPromise = validate(value);
@@ -166,6 +169,7 @@ export function useFieldControlValidation() {
166169

167170
if (result !== null) {
168171
nextState.valid = false;
172+
nextState.customError = true;
169173

170174
if (Array.isArray(result)) {
171175
validationErrors = result;
@@ -180,7 +184,7 @@ export function useFieldControlValidation() {
180184
const nextValidityData = {
181185
value,
182186
state: nextState,
183-
error: element.validationMessage ?? (Array.isArray(result) ? result[0] : result),
187+
error: defaultValidationMessage ?? (Array.isArray(result) ? result[0] : (result ?? '')),
184188
errors: validationErrors,
185189
initialValue: validityData.initialValue,
186190
};

packages/react/src/field/error/FieldError.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe('<Field.Error />', () => {
1414
},
1515
}));
1616

17-
it('should set aria-describedby on the control automatically', () => {
18-
render(
17+
it('should set aria-describedby on the control automatically', async () => {
18+
await render(
1919
<Field.Root invalid>
2020
<Field.Control />
2121
<Field.Error forceShow>Message</Field.Error>
@@ -28,8 +28,8 @@ describe('<Field.Error />', () => {
2828
);
2929
});
3030

31-
it('should show error messages by default', () => {
32-
render(
31+
it('should show error messages by default', async () => {
32+
await render(
3333
<Field.Root>
3434
<Field.Control required />
3535
<Field.Error>Message</Field.Error>
@@ -49,8 +49,8 @@ describe('<Field.Error />', () => {
4949
});
5050

5151
describe('prop: match', () => {
52-
it('should only render when `match` matches constraint validation', () => {
53-
render(
52+
it('should only render when `match` matches constraint validation', async () => {
53+
await render(
5454
<Field.Root>
5555
<Field.Control required />
5656
<Field.Error match="valueMissing">Message</Field.Error>
@@ -69,8 +69,8 @@ describe('<Field.Error />', () => {
6969
expect(screen.queryByText('Message')).not.to.equal(null);
7070
});
7171

72-
it('should show custom errors', () => {
73-
render(
72+
it('should show custom errors', async () => {
73+
await render(
7474
<Field.Root validate={() => 'error'}>
7575
<Field.Control />
7676
<Field.Error match="customError">Message</Field.Error>
@@ -89,8 +89,8 @@ describe('<Field.Error />', () => {
8989
});
9090

9191
describe('prop: forceShow', () => {
92-
it('should always render the error message', () => {
93-
render(
92+
it('should always render the error message', async () => {
93+
await render(
9494
<Field.Root>
9595
<Field.Control required />
9696
<Field.Error forceShow>Message</Field.Error>

0 commit comments

Comments
 (0)