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
TypeError: this.timerId.unref is not a function - Testing in JSDOM environment #4552
Comments
Update - After messing around for a while, using the setInterval patch above, allows the tests to run but gives me a 'Jest did not exist one second after the test run has completed' warning messaged. Using jest.useFakeTimers(); removes that error but doesnt actually allow the firestore request to complete. Here are some issues that look like it's related to: |
Related to #4557 but seems like that user isn't using Jest. Seems like you may be getting the Node bundle of Firestore when running Jest tests, if everything in Jest should be using browser APIs is there a webpack config or other setting that you can change to point to the |
@hsubox76 thanks for looking into this. From what I can see CRA extracts any setting like you suggest that would resolve the problem so I have raised an issue there. |
I've been trying to get this fix to work facebook/create-react-app#2590 (comment) but with no luck. I can see that firebase-browser.js doesn't exist anymore but is there a new equivalent? Update: Using this
I get this error
Update update: OK, after some more playing around, isNode used here: firebase-js-sdk/packages/app/index.ts Line 51 in 00c963b
Is true in a JSDOM environment, whereas it is false in an actual browser (obviously). The isNode/isBrowser logic I think needs updating. See here https://github.com/flexdinesh/browser-or-node/blob/master/src/index.js might be some good inspiration, which also provides an extra flag for isJsDom |
Is that an error? I think it's just a warning. Nothing happens in that The firebase/firebase-*.js files probably aren't the ones you want. Those are bundles for the CDN and are going to be a bit less optimized, although maybe it doesn't matter for tests. If you want to test the actual files your React application is probably using, you probably should be looking at Setting webpack (or any bundler) to prefer the So that's basically the exact same thing webpack would be doing automatically for you if could configure it. So if you can't I guess that's a solution. Doesn't seem ideal to not work "out of the box" with such a popular tool but I can't think of what we could do on our end. If anyone has any ideas, let me know. |
Reading the (old) linked issue in the CRA repo it makes sense they wouldn't want to force a default to the browser field, but I think maybe the best solution would be for CRA to provide some kind of easy option for the user to change that config without ejecting. |
Unfortunately using
throws this error If I use What's also confusing is that ReacfFire's tests use jsdom by the looks of things and aren't doing anything out of the ordinary. |
I am also running into this. The only way I am able to do e2e tests on a component that uses Firebase emulator is via Cypress (in other words in a real browser). @Mattinton any progress? |
Unfortunately not @maierson. I began yesterday experimenting with a mocking system for firebase and ditched the emulators/using real firebase completely. Hoping that in the future I'll be able to revert back to the emulators but for now mocking is just far more reliable, even if my tests become more unit testy than integration testy. |
Hey @maierson @Mattinton @hsubox76 this is a error in grpc-js! It was introduced in grpc-js v1.2.7 here: grpc/grpc-node#1688 And it is fixed with this PR: grpc/grpc-node#1709 Please include the fixed version (as soon as released) into the next firebase release :) |
We auto-update our dependencies as soon as the fix in |
Thank you! :) |
Describe your environment
Describe the problem
Hey guys, I'm trying to test my React application that uses firebase.
For testing I'm running the emulators locally and then using Jest in a JSDOM environment (Create React App setup) to run my tests. All of my auth tests run fine, however when running tests that use firestore I get the the below error:
Error: Uncaught [TypeError: this.timerId.unref is not a function]
I think by the looks of things this is linked to this issue jestjs/jest#1909
As JSDOM emulates the browser I would expect firestore to work. If I use this
setInterval().__proto__.unref = function () {};
the test works as expected.
Full stack trace:
The text was updated successfully, but these errors were encountered: