简体   繁体   English

我无法测试 firebase 函数,因为 `TypeError: Cannot read properties of undefined (reading 'DataSnapshot')`

[英]I can't test firebase functions because of `TypeError: Cannot read properties of undefined (reading 'DataSnapshot')`

I would like to run unit tests on firebase functions.我想在 firebase 函数上运行单元测试。 I created functions/test/index.test.js with the intention of testing in offline mode, and the current file content is as follows:我创建了functions/test/index.test.js,目的是离线测试,当前文件内容如下:

// 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 时,出现以下错误:

$ 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?我应该怎么办?

I ran npm ls firebase-functions and observed the following warning.我运行npm ls firebase-functions并观察到以下警告。

functions@ /path/to/project/functions
├─┬ firebase-functions-test@2.4.0
│ └── firebase-functions@3.20.0 deduped invalid: ">=3.23.0" from node_modules/firebase-functions-test
└── firebase-functions@3.20.0 invalid: ">=3.23.0" from node_modules/firebase-functions-test

npm ERR! code ELSPROBLEMS
npm ERR! invalid: firebase-functions@3.20.0 /path/to/project/functions/node_modules/firebase-functions

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/my_home/.npm/_logs/2022-09-18T09_24_27_208Z-debug-0.log

So I ran yarn add firebase-functions@3.23.0 .所以我跑了yarn add firebase-functions@3.23.0 Then, when I run the test, I no longer get the error that I got when I asked the question.然后,当我运行测试时,我不再收到我提出问题时遇到的错误。 Apparently, it was a version compatibility issue.显然,这是一个版本兼容性问题。 Thank you.谢谢你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法读取未定义的属性(读取“authService”) - TypeError: Cannot read properties of undefined (reading 'authService') Firebase:无法读取未定义的属性(读取“indexOf”) - Firebase: Cannot read properties of undefined (reading 'indexOf') Flutter 中有“TypeError: Cannot read properties of undefined (reading 'firestore')” - There is "TypeError: Cannot read properties of undefined (reading 'firestore')" in Flutter (flutter web) TypeError: Cannot read properties of undefined (reading 'auth') - (flutter web) TypeError: Cannot read properties of undefined (reading 'auth') TypeError:无法在 it.fromString 处读取未定义的属性(读取“indexOf”) - TypeError: Cannot read properties of undefined (reading 'indexOf') at it.fromString 无法读取 firebase v9 {modular} 中未定义的属性(读取“indexOf”) - Cannot read properties of undefined (reading 'indexOf') in firebase v9 {modular} TypeError:无法读取 null 的属性(读取“uid”) - TypeError: Cannot read properties of null (reading 'uid') TypeError:无法读取未定义的属性(读取存储) - TypeError:Cannot read propreties of undefined (reading storage) Firebase Cloud Functions - 在制作 Telegram Bot 时出现“TypeError:无法读取未定义的属性‘slice’” - Firebase Cloud Functions - "TypeError: Cannot read property 'slice' of undefined" while making Telegram Bot typeerror cannot read properties of null reading uid,我没有异步代码和登录用户有什么想法? - typeerror cannot read properties of null reading uid, I have no asynchronous code and the users logged in any ideas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM