TheBrainFamily / wait-for-expect

Wait for expectation to be true, useful for integration and end to end testing. Integral part of react-testing-library.
MIT License
293 stars 31 forks source link

Fake timers are not detected at jest@28 #36

Open goooseman opened 1 year ago

goooseman commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch wait-for-expect@3.0.2 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/wait-for-expect/lib/helpers.js b/node_modules/wait-for-expect/lib/helpers.js
index 27d63b7..aee6aa4 100644
--- a/node_modules/wait-for-expect/lib/helpers.js
+++ b/node_modules/wait-for-expect/lib/helpers.js
@@ -15,7 +15,9 @@ var globalObj = typeof window === "undefined" ? global : window; // Currently th

 function runWithRealTimers(callback) {
   var usingJestFakeTimers = // eslint-disable-next-line no-underscore-dangle
-  globalObj.setTimeout._isMockFunction && typeof jest !== "undefined";
+    typeof jest !== 'undefined' &&
+    setTimeout.clock != null &&
+    typeof setTimeout.clock.Date === 'function';

   if (usingJestFakeTimers) {
     jest.useRealTimers();

This issue body was partially generated by patch-package.

aarowman commented 1 year ago

+1 I am also having this issue

aarowman commented 2 weeks ago

Any updates on this item? It's been over a year :(