From 5ec02f09ca516432184979ce9c9f71e19896c7e3 Mon Sep 17 00:00:00 2001 From: Andrew Hill Date: Fri, 16 Aug 2019 14:53:03 +1000 Subject: [PATCH] Add asyncUtilTimeout to config to allow custom default async timeout --- src/config.js | 1 + src/wait-for-dom-change.js | 2 +- src/wait-for-element-to-be-removed.js | 2 +- src/wait-for-element.js | 2 +- src/wait.js | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/config.js b/src/config.js index b27b9fd1..c09c5085 100644 --- a/src/config.js +++ b/src/config.js @@ -3,6 +3,7 @@ // './queries' are query functions. let config = { testIdAttribute: 'data-testid', + asyncUtilTimeout: 4500, // this is to support React's async `act` function. // forcing react-testing-library to wrap all async functions would've been // a total nightmare (consider wrapping every findBy* query and then also diff --git a/src/wait-for-dom-change.js b/src/wait-for-dom-change.js index 86f3c7df..71472383 100644 --- a/src/wait-for-dom-change.js +++ b/src/wait-for-dom-change.js @@ -9,7 +9,7 @@ import {getConfig} from './config' function waitForDomChange({ container = getDocument(), - timeout = 4500, + timeout = getConfig().asyncUtilTimeout, mutationObserverOptions = { subtree: true, childList: true, diff --git a/src/wait-for-element-to-be-removed.js b/src/wait-for-element-to-be-removed.js index e269599e..86e4b1fc 100644 --- a/src/wait-for-element-to-be-removed.js +++ b/src/wait-for-element-to-be-removed.js @@ -11,7 +11,7 @@ function waitForElementToBeRemoved( callback, { container = getDocument(), - timeout = 4500, + timeout = getConfig().asyncUtilTimeout, mutationObserverOptions = { subtree: true, childList: true, diff --git a/src/wait-for-element.js b/src/wait-for-element.js index 5dc676e3..352f36ae 100644 --- a/src/wait-for-element.js +++ b/src/wait-for-element.js @@ -11,7 +11,7 @@ function waitForElement( callback, { container = getDocument(), - timeout = 4500, + timeout = getConfig().asyncUtilTimeout, mutationObserverOptions = { subtree: true, childList: true, diff --git a/src/wait.js b/src/wait.js index 379c3f52..193aa057 100644 --- a/src/wait.js +++ b/src/wait.js @@ -1,7 +1,7 @@ import waitForExpect from 'wait-for-expect' import {getConfig} from './config' -function wait(callback = () => {}, {timeout = 4500, interval = 50} = {}) { +function wait(callback = () => {}, {timeout = getConfig().asyncUtilTimeout, interval = 50} = {}) { return waitForExpect(callback, timeout, interval) }