-
-
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 5 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,4 @@ | ||
| export default async function delayFrame() { | ||
| return Promise.resolve(); | ||
| return Promise.resolve(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { macroTask } from '../../src/hooks/useNotifyWatch'; | ||
| import { act } from '@testing-library/react'; | ||
|
|
||
| export default async (timeout: number = 10) => { | ||
|
|
@@ -7,6 +8,13 @@ export default async (timeout: number = 10) => { | |
| }; | ||
|
|
||
| export async function waitFakeTime(timeout: number = 10) { | ||
| await act(async () => { | ||
| await new Promise<void>(resolve => { | ||
| macroTask(resolve); | ||
| jest.advanceTimersByTime(11); | ||
| }); | ||
| }); | ||
|
Comment on lines
+10
to
+22
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.
Line 10-22 的两次固定 可参考的最小改法 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 |
||
|
|
||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| jest.advanceTimersByTime(timeout); | ||
|
|
||
| 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>(); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.