react-component / react-component/field-form

关于测试代码中使用simulate方法需要调用timeout的疑问

Open
#131 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
286
Avg merge
4d 16h
Merged PRs (30d)
1

Description

请教作者一个问题
我在看测试代码的时候发现

timeout.ts 方法

export default (timeout: number = 0) => {
  return new Promise(resolve => {
    setTimeout(resolve, timeout);
  });
};

tests/index.test.js

await changeValue(getField(wrapper), 'Bamboo');
wrapper.find('button').simulate('submit');
await timeout();

我自己在测试的时候发现如果不执行await timeout(),那么onFinish就不会被调用。
这是为什么呢

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/common/timeout.ts and tests/index.test.js around lines 244-246. Trace the submit simulation and the timing of the onFinish callback, then check the related test setup and React event behavior. Done means documenting why await timeout() is required or confirming that the test can avoid it.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
testing-qa
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.