I would like to run unit tests on firebase functions. I created functions/test/index.test.js with the intention of testing in offline mode, and the current file content is as follows:
// The content is only one line.
const test = require("firebase-functions-test")();
When I run jest with the above file, I get the following error:
$ jest
FAIL test/index.test.js
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'DataSnapshot')
> 1 | const test = require("firebase-functions-test")();
| ^
2 |
at Object.<anonymous> (node_modules/firebase-functions-test/lib/cloudevent/generate.js:26:45)
at Object.<anonymous> (node_modules/firebase-functions-test/lib/v2.js:25:20)
at Object.<anonymous> (node_modules/firebase-functions-test/lib/main.js:26:14)
at Object.<anonymous> (node_modules/firebase-functions-test/lib/features.js:4:16)
at Object.<anonymous>.module.exports (node_modules/firebase-functions-test/lib/index.js:30:20)
at Object.<anonymous> (test/index.test.js:1:1)
Something does not seem to be set correctly before the test error. What should I do?