-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using jest.useFakeTimers() in a test causes firebase-admin/firestore promises to no longer resolve #2283
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Hi @curtis-jotson , can you explain more which part of the code experiences time out? For example,
Or
|
Hello @cherylEnkidu, sorry for the delay. This part experiences the timeout:
when this part is uncommented:
|
Hi @curtis-jotson , it could be possible that faking time changes some underlining javascript and unfortunately we can only guaranteeing the performance on production environment. |
It does this when connected to the online environment as well, not just the emulators. It's an issue with library halting data access when "time" isn't moving. No other data access library I've used exhibits this behaviour and it's stopping me from being able to TDD my code effectively. |
Sorry for the confusion here. The team can only guarantee the performance on the production environment which including using the real time. It is possible changing the system time fails some of the security checks in the backend. |
I encountered the same problem as this one. I only wanted to mock new Date(), so by providing everything except for Date, which is mentioned at https://jestjs.io/ja/docs/jest-object#jestusefaketimersfaketimersconfig, to the doNotFake option, the test started working jest.useFakeTimers({
doNotFake: [
"hrtime",
"nextTick",
"performance",
"queueMicrotask",
"requestAnimationFrame",
"cancelAnimationFrame",
"requestIdleCallback",
"cancelIdleCallback",
"setImmediate",
"clearImmediate",
"setInterval",
"clearInterval",
"setTimeout",
"clearTimeout",
],
now: new Date("2022/01/01 0:00:00"),
}); |
Woah thanks! I've been struggling with this for a long time!! I had to mock out Date.now() as a workaround previously. |
[READ] Step 1: Are you in the right place?
template.
with the firebase tag.
google group.
of the above categories, reach out to the personalized
Firebase support channel.
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Set up a jest test against firebase-admin/firestore running against a local emulator. If faking out date and timers with jest.useFakeTimers(), a very common way of date/time mocking, suddenly Firebase promises are no longer resolving. Date mocking and faking is very common in the TDD world and the data access library should continue to respond even if "time" isn't moving.
Relevant Code:
jest.UseFakeTimers()
call inbeforeAll
The text was updated successfully, but these errors were encountered: