You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
It is possible for previously queued code to execute between the restore and override steps in restoreFor, which means they unexpectedly use the native time functions.
I found this when using delay (which in turn uses restoreFor).
import{FakeTime,NativeTime,delay}from"https://deno.land/x/mock@v0.9.4/time.ts";functionisNative(prefix){console.log(prefix,setTimeout===NativeTime.setTimeout ? "native" : "not native");}asyncfunctionfun(){awaitPromise.resolve();// I expect setTimeout to be fake here but it is notisNative("fun");}constft=newFakeTime();isNative("before");fun();awaitdelay(0);isNative("after");// outputs:// before not native// fun native// after not native
The text was updated successfully, but these errors were encountered:
fun is asynchronous. Without awaiting it before calling the delay function that restores native time, there is a chance that native time would be restored temporarily while the code in fun is running. You could encounter a similar issue if you were to call ft.restore() after fun without awaiting it.
I realize how it works, but my intent was to point out that someone using the library may not immediately figure out that delay/restoreFor has such a side effect. Whether this needs a fix, the choice is yours.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It is possible for previously queued code to execute between the restore and override steps in
restoreFor
, which means they unexpectedly use the native time functions.mock/time.ts
Lines 337 to 342 in cf21e99
I found this when using
delay
(which in turn usesrestoreFor
).The text was updated successfully, but these errors were encountered: