Skip to content

Commit 9e53278

Browse files
zombieJclaude
andcommitted
test: update tests for delayFrame with macroTask changes
- Add changeValueWithMockTimer helper for tests using fake timers - Update 'touched' test to use fake timers for consistent timing - Remove trailing whitespace in dependencies.test.tsx Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e9da67c commit 9e53278

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

tests/common/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import timeout from './timeout';
1+
import timeout, { waitFakeTime } from './timeout';
22
import { matchNamePath } from '../../src/utils/valueUtil';
33
import { fireEvent, act } from '@testing-library/react';
44

@@ -46,6 +46,13 @@ export async function changeValue(wrapper: HTMLElement, value: string | string[]
4646
}
4747
}
4848

49+
export async function changeValueWithMockTimer(wrapper: HTMLElement, value: string | string[]) {
50+
const promise = changeValue(wrapper, value);
51+
52+
await waitFakeTime();
53+
return promise;
54+
}
55+
4956
export function matchError(
5057
wrapper: HTMLElement,
5158
error?: boolean | string,

tests/dependencies.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { FormInstance } from '../src';
33
import Form, { Field } from '../src';
44
import { waitFakeTime } from './common/timeout';
55
import InfoField, { Input } from './common/InfoField';
6-
import { changeValue, matchError, getInput } from './common';
6+
import { changeValue, matchError, getInput, changeValueWithMockTimer } from './common';
77
import { fireEvent, render } from '@testing-library/react';
88

99
describe('Form.Dependencies', () => {
@@ -12,6 +12,7 @@ describe('Form.Dependencies', () => {
1212
});
1313

1414
it('touched', async () => {
15+
jest.useFakeTimers();
1516
const form = React.createRef<FormInstance>();
1617

1718
const { container } = render(
@@ -24,12 +25,13 @@ describe('Form.Dependencies', () => {
2425
);
2526

2627
// Not trigger if not touched
27-
await changeValue(getInput(container, 0), ['bamboo', '']);
28+
await changeValueWithMockTimer(getInput(container, 0), ['bamboo', '']);
2829
matchError(getInput(container, 1, true), false);
2930

3031
// Trigger if touched
3132
form.current?.setFields([{ name: 'field_2', touched: true }]);
32-
await changeValue(getInput(container, 0), ['bamboo', '']);
33+
34+
await changeValueWithMockTimer(getInput(container, 0), ['bamboo', '']);
3335
matchError(getInput(container, 1, true), true);
3436
});
3537

@@ -260,7 +262,6 @@ describe('Form.Dependencies', () => {
260262

261263
<Field shouldUpdate={() => false}>
262264
{() => {
263-
264265
counter += 1;
265266
return null;
266267
}}

0 commit comments

Comments
 (0)