简体   繁体   English

如何在 React 测试库中全局设置 waitFor 选项?

[英]How to set waitFor options globally in React Testing Library?

I was taking a look to the waitFor documentation and I was wondering if there is any way to configure it globally, for example in the jest.config or in the command used to launch the test suite?我正在查看waitFor 文档,我想知道是否有任何方法可以全局配置它,例如在jest.config或用于启动测试套件的命令中?

I need to increase the timeout in every test and it is a bit annoying.我需要在每次测试中增加超时时间,这有点烦人。

Per the documentation , the configuration option for the timeouts on the various asynchronous utilities is asyncUtilTimeout :根据文档,各种异步实用程序的超时配置选项是asyncUtilTimeout

asyncUtilTimeout

The global timeout value in milliseconds used by waitFor utilities. waitFor实用程序使用的全局超时值(以毫秒为单位)。 Defaults to 1000ms.默认为 1000 毫秒。

You can configure this using the configure function, eg in a setupTests.js file:您可以使用configure函数进行configure ,例如在setupTests.js文件中:

import { configure } from "@testing-library/react";

configure({ asyncUtilTimeout: 5000 });

You could create a helper function, no?你可以创建一个辅助函数,不是吗?


export function wrappedWaitFor(cb, opts = {}) {
  waitFor(cb, { ...opts, timeout: 10000 });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM