TypeError: this.timerId.unref is not a function – Testing in JSDOM environment

Describe your environment

  • Operating System version: macOS
  • Browser version: JSDOM
  • Firebase SDK version: 8.2.9
  • Firebase Product: firestore

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 facebook/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:

    Error: Uncaught [TypeError: this.timerId.unref is not a function]
        at reportException (C:\Users\Matt\Dev\gradeguide-web\node_modules\jsdom\lib\jsdom\living\helpers\runtime-script-errors.js:62:24)
        at Timeout.task [as _onTimeout] (C:\Users\Matt\Dev\gradeguide-web\node_modules\jsdom\lib\jsdom\browser\Window.js:396:9)
        at listOnTimeout (internal/timers.js:554:17)
        at processTimers (internal/timers.js:497:7) TypeError: this.timerId.unref is not a function
        at BackoffTimeout.unref (C:\Users\Matt\Dev\gradeguide-web\node_modules\@grpc\grpc-js\src\backoff-timeout.ts:117:18)
        at new ResolvingLoadBalancer (C:\Users\Matt\Dev\gradeguide-web\node_modules\@grpc\grpc-js\src\resolving-load-balancer.ts:199:25)
        at new ChannelImplementation (C:\Users\Matt\Dev\gradeguide-web\node_modules\@grpc\grpc-js\src\channel.ts:242:34)
        at new Client (C:\Users\Matt\Dev\gradeguide-web\node_modules\@grpc\grpc-js\src\client.ts:146:30)
        at new ServiceClientImpl (C:\Users\Matt\Dev\gradeguide-web\node_modules\@grpc\grpc-js\src\make-client.ts:128:3)
        at GrpcConnection.Object.<anonymous>.GrpcConnection.ensureActiveStub (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\firestore\src\platform\node\grpc_connection.ts:90:25)
        at GrpcConnection.Object.<anonymous>.GrpcConnection.openStream (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\firestore\src\platform\node\grpc_connection.ts:175:23) 
        at PersistentWriteStream.Object.<anonymous>.PersistentWriteStream.startRpc (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\firestore\src\remote\persistent_stream.ts:710:28)
        at PersistentWriteStream.Object.<anonymous>.PersistentStream.startStream (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\firestore\src\remote\persistent_stream.ts:443:24)
        at call (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\firestore\src\remote\persistent_stream.ts:420:16)
        at call (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\node_modules\google-closure-library\closure\goog\promise\promise.js:826:22)
        at goog.Promise.invokeCallback_ (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\node_modules\google-closure-library\closure\goog\promise\promise.js:1166:5)
        at executeCallback_ (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\node_modules\google-closure-library\closure\goog\promise\promise.js:1140:5)
        at D.call [as gc] (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\node_modules\google-closure-library\closure\goog\promise\promise.js:1111:5)
        at xc (C:\Users\Matt\Dev\gradeguide-web\node_modules\@firebase\node_modules\google-closure-library\closure\goog\async\run.js:124:7)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)

      at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
      at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:28)
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:396:9)```

1 possible answer(s) on “TypeError: this.timerId.unref is not a function – Testing in JSDOM environment