-
-
Notifications
You must be signed in to change notification settings - Fork 280
fix: Rule deps on the useWatch #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9a72b49
026e609
aabcf72
ffed1b2
6f5d2c4
1a34250
8c0135d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import raf from '@rc-component/util/lib/raf'; | ||
|
|
||
| export default async function delayFrame() { | ||
| return new Promise<void>(resolve => { | ||
| raf(() => { | ||
| resolve(); | ||
| }); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default async function delayFrame() { | ||
| return Promise.resolve(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ import InfoField, { Input } from './common/InfoField'; | |
| import { changeValue, getInput } from './common'; | ||
| import timeout from './common/timeout'; | ||
|
|
||
| jest.mock('../src/utils/delayUtil'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥要 mock,delayFrame 里面的 raf 不能在 test 中用吗,raf 有什么功能
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. raf 见评论描述,测试里 mock 是因为 raf 需要 adv timer。而测试里有很多测试都是从 rc-form 里过来的,所以用的是真实的 timeout 导致测试会卡死。所以对部分老测试使用 mock 来保持时序,其他比较新的测试写法 fakeTimer 的不动也自己过了。 |
||
|
|
||
| describe('Form.List', () => { | ||
| const form = React.createRef<FormInstance>(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waitFakeTime在共享 helper 中无条件多推进 22ms,容易影响无关测试时序。Line 10-22 的两次固定
11ms推进会作用于所有调用方,不仅仅是useWatch场景;这可能提前触发其它定时逻辑,导致测试“误通过”或时序不稳定。建议把额外帧推进改为可配置参数,仅在需要的用例里显式开启。可参考的最小改法
export async function waitFakeTime(timeout: number = 10) { - await act(async () => { - await new Promise<void>(resolve => { - setTimeout(resolve, 11); - jest.advanceTimersByTime(11); - }); - }); - - await act(async () => { - await new Promise<void>(resolve => { - setTimeout(resolve, 11); - jest.advanceTimersByTime(11); - }); - }); +export async function waitFakeTime(timeout: number = 10, preFrames: number = 0) { + for (let i = 0; i < preFrames; i += 1) { + await act(async () => { + await new Promise<void>(resolve => { + setTimeout(resolve, 11); + jest.advanceTimersByTime(11); + }); + }); + } await act(async () => { await Promise.resolve(); jest.advanceTimersByTime(timeout); await Promise.resolve(); }); }🤖 Prompt for AI Agents